forked from datajoint/datajoint-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_alter.py
More file actions
46 lines (41 loc) · 1.59 KB
/
test_alter.py
File metadata and controls
46 lines (41 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from nose.tools import assert_equal, assert_not_equal
from .schema import *
@schema
class Experiment(dj.Imported):
original_definition = """ # information about experiments
-> Subject
experiment_id :smallint # experiment number for this subject
---
experiment_date :date # date when experiment was started
-> [nullable] User
data_path="" :varchar(255) # file path to recorded data
notes="" :varchar(2048) # e.g. purpose of experiment
entry_time=CURRENT_TIMESTAMP :timestamp # automatic timestamp
"""
definition1 = """ # Experiment
-> Subject
experiment_id :smallint # experiment number for this subject
---
data_path : int # some number
extra=null : longblob # just testing
-> [nullable] User
subject_notes=null :varchar(2048) # {notes} e.g. purpose of experiment
entry_time=CURRENT_TIMESTAMP :timestamp # automatic timestamp
"""
def test_alter():
original = schema.connection.query(
"SHOW CREATE TABLE " + Experiment.full_table_name
).fetchone()[1]
Experiment.definition = Experiment.definition1
Experiment.alter(prompt=False)
altered = schema.connection.query(
"SHOW CREATE TABLE " + Experiment.full_table_name
).fetchone()[1]
assert_not_equal(original, altered)
Experiment.definition = Experiment.original_definition
Experiment().alter(prompt=False)
restored = schema.connection.query(
"SHOW CREATE TABLE " + Experiment.full_table_name
).fetchone()[1]
assert_not_equal(altered, restored)
assert_equal(original, restored)