Skip to content

Commit d815e82

Browse files
committed
First pass at migrating test_declare
1 parent fbecd8a commit d815e82

File tree

1 file changed

+57
-40
lines changed

1 file changed

+57
-40
lines changed

tests/test_declare.py

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
from datajoint.declare import declare
66

77

8-
class TestDeclare:
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+
920

10-
@classmethod
11-
def setup_class(cls):
12-
cls.auto = Auto()
13-
cls.auto.fill()
14-
cls.user = User()
15-
cls.subject = Subject()
16-
cls.experiment = Experiment()
17-
cls.trial = Trial()
18-
cls.ephys = Ephys()
19-
cls.channel = Ephys.Channel()
21+
class TestDeclare:
2022

2123
def test_schema_decorator(self, schema_any):
2224
assert issubclass(Subject, dj.Lookup)
@@ -58,8 +60,10 @@ def test_describe_dependencies(self, schema_any):
5860
s2 = declare(rel.full_table_name, rel.describe(), context)
5961
assert s1 == s2
6062

61-
def test_part(self, schema_any):
62-
# Lookup and part with the same name. See issue #365
63+
def test_part(self):
64+
"""
65+
Lookup and part with the same name. See issue #365
66+
"""
6367
local_schema = dj.Schema(schema.database)
6468

6569
@local_schema
@@ -180,20 +184,20 @@ def test_dependencies(self, schema_any):
180184
def test_descendants_only_contain_part_table(self, schema_any):
181185
"""issue #927"""
182186

183-
@schema
187+
@schema_any
184188
class A(dj.Manual):
185189
definition = """
186190
a: int
187191
"""
188192

189-
@schema
193+
@schema_any
190194
class B(dj.Manual):
191195
definition = """
192196
-> A
193197
b: int
194198
"""
195199

196-
@schema
200+
@schema_any
197201
class Master(dj.Manual):
198202
definition = """
199203
table_master: int
@@ -211,84 +215,94 @@ class Part(dj.Part):
211215
"`djtest_test1`.`master__part`",
212216
]
213217

214-
@raises(dj.DataJointError)
215-
def test_bad_attribute_name(self):
216-
@schema
218+
def test_bad_attribute_name(self, schema_any):
219+
217220
class BadName(dj.Manual):
218221
definition = """
219222
Bad_name : int
220223
"""
221224

222-
@raises(dj.DataJointError)
223-
def test_bad_fk_rename(self):
225+
with pytest.raises(dj.DataJointError):
226+
schema_any(BadName)
227+
228+
def test_bad_fk_rename(self, schema_any):
224229
"""issue #381"""
225230

226-
@schema
227231
class A(dj.Manual):
228232
definition = """
229233
a : int
230234
"""
231235

232-
@schema
233236
class B(dj.Manual):
234237
definition = """
235238
b -> A # invalid, the new syntax is (b) -> A
236239
"""
237240

238-
@raises(dj.DataJointError)
239-
def test_primary_nullable_foreign_key(self):
240-
@schema
241+
schema_any(A)
242+
with pytest.raises(dj.DataJointError):
243+
schema_any(B)
244+
245+
def test_primary_nullable_foreign_key(self, schema_any):
246+
241247
class Q(dj.Manual):
242248
definition = """
243249
-> [nullable] Experiment
244250
"""
245251

246-
@raises(dj.DataJointError)
247-
def test_invalid_foreign_key_option(self):
248-
@schema
252+
with pytest.raises(dj.DataJointError):
253+
schema_any(Q)
254+
255+
def test_invalid_foreign_key_option(self, schema_any):
256+
249257
class R(dj.Manual):
250258
definition = """
251259
-> Experiment
252260
----
253261
-> [optional] User
254262
"""
255263

256-
@raises(dj.DataJointError)
257-
def test_unsupported_datatype(self):
258-
@schema
264+
with pytest.raises(dj.DataJointError):
265+
schema_any(R)
266+
267+
def test_unsupported_datatype(self, schema_any):
268+
259269
class Q(dj.Manual):
260270
definition = """
261271
experiment : int
262272
---
263273
description : text
264274
"""
265275

266-
def test_int_datatype(self):
267-
@schema
276+
with pytest.raises(dj.DataJointError):
277+
schema_any(Q)
278+
279+
def test_int_datatype(self, schema_any):
280+
281+
@schema_any
268282
class Owner(dj.Manual):
269283
definition = """
270284
ownerid : int
271285
---
272286
car_count : integer
273287
"""
274288

275-
@raises(dj.DataJointError)
276-
def test_unsupported_int_datatype(self):
277-
@schema
289+
def test_unsupported_int_datatype(self, schema_any):
290+
278291
class Driver(dj.Manual):
279292
definition = """
280293
driverid : tinyint
281294
---
282295
car_count : tinyinteger
283296
"""
284297

285-
@raises(dj.DataJointError)
286-
def test_long_table_name(self):
298+
with pytest.raises(dj.DataJointError):
299+
schema_any(Driver)
300+
301+
def test_long_table_name(self, schema_any):
287302
"""
288303
test issue #205 -- reject table names over 64 characters in length
289304
"""
290305

291-
@schema
292306
class WhyWouldAnyoneCreateATableNameThisLong(dj.Manual):
293307
definition = """
294308
master : int
@@ -298,3 +312,6 @@ class WithSuchALongPartNameThatItCrashesMySQL(dj.Part):
298312
definition = """
299313
-> (master)
300314
"""
315+
316+
with pytest.raises(dj.DataJointError):
317+
schema_any(WhyWouldAnyoneCreateATableNameThisLong)

0 commit comments

Comments
 (0)