55from datajoint .declare import declare
66
77
8- @pytest .fixture
9- def schema_any (schema_any ):
10- auto = Auto ()
11- auto .fill ()
12- user = User ()
13- subject = Subject ()
14- experiment = Experiment ()
15- trial = Trial ()
16- ephys = Ephys ()
17- channel = Ephys .Channel ()
18- yield schema_any
19-
20-
218class TestDeclare :
22-
239 def test_schema_decorator (self , schema_any ):
2410 assert issubclass (Subject , dj .Lookup )
2511 assert not issubclass (Subject , dj .Part )
@@ -60,11 +46,11 @@ def test_describe_dependencies(self, schema_any):
6046 s2 = declare (rel .full_table_name , rel .describe (), context )
6147 assert s1 == s2
6248
63- def test_part (self ):
49+ def test_part (self , schema_any ):
6450 """
6551 Lookup and part with the same name. See issue #365
6652 """
67- local_schema = dj .Schema (schema .database )
53+ local_schema = dj .Schema (schema_any .database )
6854
6955 @local_schema
7056 class Type (dj .Lookup ):
@@ -86,118 +72,144 @@ class Type(dj.Part):
8672 """
8773
8874 def test_attributes (self , schema_any ):
89- # test autoincrement declaration
75+ """
76+ Test autoincrement declaration
77+ """
78+ auto = Auto ()
79+ auto .fill ()
80+ user = User ()
81+ subject = Subject ()
82+ experiment = Experiment ()
83+ trial = Trial ()
84+ ephys = Ephys ()
85+ channel = Ephys .Channel ()
86+
9087 assert auto .heading .names == ["id" , "name" ]
9188 assert auto .heading .attributes ["id" ].autoincrement
9289
9390 # test attribute declarations
94- assert (
95- subject .heading .names ==
96- ["subject_id" , "real_id" , "species" , "date_of_birth" , "subject_notes" ])
91+ assert subject .heading .names == [
92+ "subject_id" ,
93+ "real_id" ,
94+ "species" ,
95+ "date_of_birth" ,
96+ "subject_notes" ,
97+ ]
9798 assert subject .primary_key == ["subject_id" ]
9899 assert subject .heading .attributes ["subject_id" ].numeric
99100 assert not subject .heading .attributes ["real_id" ].numeric
100101
101- assert (
102- experiment .heading .names ==
103- [
104- "subject_id" ,
105- "experiment_id" ,
106- "experiment_date" ,
107- "username" ,
108- "data_path" ,
109- "notes" ,
110- "entry_time" ,
111- ])
102+ assert experiment .heading .names == [
103+ "subject_id" ,
104+ "experiment_id" ,
105+ "experiment_date" ,
106+ "username" ,
107+ "data_path" ,
108+ "notes" ,
109+ "entry_time" ,
110+ ]
112111 assert experiment .primary_key == ["subject_id" , "experiment_id" ]
113112
114- assert (
115- trial .heading .names == # tests issue #516
116- ["animal" , "experiment_id" , "trial_id" , "start_time" ])
113+ assert trial .heading .names == [ # tests issue #516
114+ "animal" ,
115+ "experiment_id" ,
116+ "trial_id" ,
117+ "start_time" ,
118+ ]
117119 assert trial .primary_key == ["animal" , "experiment_id" , "trial_id" ]
118120
119- assert (
120- ephys .heading .names ==
121- ["animal" , "experiment_id" , "trial_id" , "sampling_frequency" , "duration" ])
121+ assert ephys .heading .names == [
122+ "animal" ,
123+ "experiment_id" ,
124+ "trial_id" ,
125+ "sampling_frequency" ,
126+ "duration" ,
127+ ]
122128 assert ephys .primary_key == ["animal" , "experiment_id" , "trial_id" ]
123129
124- assert (
125- channel .heading .names ==
126- ["animal" , "experiment_id" , "trial_id" , "channel" , "voltage" , "current" ])
127- assert (
128- channel .primary_key == ["animal" , "experiment_id" , "trial_id" , "channel" ])
130+ assert channel .heading .names == [
131+ "animal" ,
132+ "experiment_id" ,
133+ "trial_id" ,
134+ "channel" ,
135+ "voltage" ,
136+ "current" ,
137+ ]
138+ assert channel .primary_key == ["animal" , "experiment_id" , "trial_id" , "channel" ]
129139 assert channel .heading .attributes ["voltage" ].is_blob
130140
131141 def test_dependencies (self , schema_any ):
142+ auto = Auto ()
143+ auto .fill ()
144+ user = User ()
145+ subject = Subject ()
146+ experiment = Experiment ()
147+ trial = Trial ()
148+ ephys = Ephys ()
149+ channel = Ephys .Channel ()
150+
132151 assert experiment .full_table_name in user .children (primary = False )
133152 assert set (experiment .parents (primary = False )) == {user .full_table_name }
134153 assert experiment .full_table_name in user .children (primary = False )
135154 assert set (experiment .parents (primary = False )) == {user .full_table_name }
136- assert (
137- set (
138- s .full_table_name
139- for s in experiment .parents (primary = False , as_objects = True )
140- ) ==
141- {user .full_table_name })
155+ assert set (
156+ s .full_table_name
157+ for s in experiment .parents (primary = False , as_objects = True )
158+ ) == {user .full_table_name }
142159
143160 assert experiment .full_table_name in subject .descendants ()
144- assert (experiment .full_table_name
145- in {s .full_table_name for s in subject .descendants (as_objects = True )})
161+ assert experiment .full_table_name in {
162+ s .full_table_name for s in subject .descendants (as_objects = True )
163+ }
146164 assert subject .full_table_name in experiment .ancestors ()
147- assert (subject .full_table_name
148- in {s .full_table_name for s in experiment .ancestors (as_objects = True )})
165+ assert subject .full_table_name in {
166+ s .full_table_name for s in experiment .ancestors (as_objects = True )
167+ }
149168
150169 assert trial .full_table_name in experiment .descendants ()
151- assert (trial .full_table_name
152- in {s .full_table_name for s in experiment .descendants (as_objects = True )})
170+ assert trial .full_table_name in {
171+ s .full_table_name for s in experiment .descendants (as_objects = True )
172+ }
153173 assert experiment .full_table_name in trial .ancestors ()
154- assert (experiment .full_table_name
155- in {s .full_table_name for s in trial .ancestors (as_objects = True )})
156-
157- assert (
158- set (trial .children (primary = True )) ==
159- {ephys .full_table_name , trial .Condition .full_table_name })
174+ assert experiment .full_table_name in {
175+ s .full_table_name for s in trial .ancestors (as_objects = True )
176+ }
177+
178+ assert set (trial .children (primary = True )) == {
179+ ephys .full_table_name ,
180+ trial .Condition .full_table_name ,
181+ }
160182 assert set (trial .parts ()) == {trial .Condition .full_table_name }
161- assert (
162- set ( s . full_table_name for s in trial .parts ( as_objects = True )) ==
163- { trial . Condition . full_table_name })
183+ assert set ( s . full_table_name for s in trial . parts ( as_objects = True )) == {
184+ trial .Condition . full_table_name
185+ }
164186 assert set (ephys .parents (primary = True )) == {trial .full_table_name }
165- assert (
166- set (
167- s .full_table_name for s in ephys .parents (primary = True , as_objects = True )
168- ) ==
169- {trial .full_table_name })
187+ assert set (
188+ s .full_table_name for s in ephys .parents (primary = True , as_objects = True )
189+ ) == {trial .full_table_name }
170190 assert set (ephys .children (primary = True )) == {channel .full_table_name }
171- assert (
172- set (
173- s .full_table_name for s in ephys .children (primary = True , as_objects = True )
174- ) ==
175- {channel .full_table_name })
191+ assert set (
192+ s .full_table_name for s in ephys .children (primary = True , as_objects = True )
193+ ) == {channel .full_table_name }
176194 assert set (channel .parents (primary = True )) == {ephys .full_table_name }
177- assert (
178- set (
179- s .full_table_name
180- for s in channel .parents (primary = True , as_objects = True )
181- ) ==
182- {ephys .full_table_name })
195+ assert set (
196+ s .full_table_name for s in channel .parents (primary = True , as_objects = True )
197+ ) == {ephys .full_table_name }
183198
184199 def test_descendants_only_contain_part_table (self , schema_any ):
185200 """issue #927"""
186201
187- @schema_any
188202 class A (dj .Manual ):
189203 definition = """
190204 a: int
191205 """
192206
193- @schema_any
194207 class B (dj .Manual ):
195208 definition = """
196209 -> A
197210 b: int
198211 """
199212
200- @schema_any
201213 class Master (dj .Manual ):
202214 definition = """
203215 table_master: int
@@ -209,14 +221,17 @@ class Part(dj.Part):
209221 -> B
210222 """
211223
224+ context = dict (A = A , B = B , Master = Master )
225+ schema_any (A , context = context )
226+ schema_any (B , context = context )
227+ schema_any (Master , context = context )
212228 assert A .descendants () == [
213229 "`djtest_test1`.`a`" ,
214230 "`djtest_test1`.`b`" ,
215231 "`djtest_test1`.`master__part`" ,
216232 ]
217233
218234 def test_bad_attribute_name (self , schema_any ):
219-
220235 class BadName (dj .Manual ):
221236 definition = """
222237 Bad_name : int
@@ -243,7 +258,6 @@ class B(dj.Manual):
243258 schema_any (B )
244259
245260 def test_primary_nullable_foreign_key (self , schema_any ):
246-
247261 class Q (dj .Manual ):
248262 definition = """
249263 -> [nullable] Experiment
@@ -253,7 +267,6 @@ class Q(dj.Manual):
253267 schema_any (Q )
254268
255269 def test_invalid_foreign_key_option (self , schema_any ):
256-
257270 class R (dj .Manual ):
258271 definition = """
259272 -> Experiment
@@ -265,7 +278,6 @@ class R(dj.Manual):
265278 schema_any (R )
266279
267280 def test_unsupported_datatype (self , schema_any ):
268-
269281 class Q (dj .Manual ):
270282 definition = """
271283 experiment : int
@@ -277,7 +289,6 @@ class Q(dj.Manual):
277289 schema_any (Q )
278290
279291 def test_int_datatype (self , schema_any ):
280-
281292 @schema_any
282293 class Owner (dj .Manual ):
283294 definition = """
@@ -287,7 +298,6 @@ class Owner(dj.Manual):
287298 """
288299
289300 def test_unsupported_int_datatype (self , schema_any ):
290-
291301 class Driver (dj .Manual ):
292302 definition = """
293303 driverid : tinyint
0 commit comments