Skip to content

Commit b7ce668

Browse files
committed
Format with black
1 parent 07553a2 commit b7ce668

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

tests/test_relation.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,26 @@ def test_contents(user, subject):
7777
u = subject.fetch(order_by=["subject_id"])
7878
assert list(u["subject_id"]) == sorted([s[0] for s in subject.contents])
7979

80+
8081
def test_misnamed_attribute1(user):
8182
with pytest.raises(dj.DataJointError):
8283
user.insert([dict(username="Bob"), dict(user="Alice")])
8384

85+
8486
def test_misnamed_attribute2(user):
8587
with pytest.raises(KeyError):
8688
user.insert1(dict(user="Bob"))
8789

90+
8891
def test_extra_attribute1(user):
8992
with pytest.raises(KeyError):
9093
user.insert1(dict(username="Robert", spouse="Alice"))
9194

95+
9296
def test_extra_attribute2(user):
9397
user.insert1(dict(username="Robert", spouse="Alice"), ignore_extra_fields=True)
9498

99+
95100
def test_missing_definition(schema_any):
96101
class MissingDefinition(dj.Manual):
97102
definitions = """ # misspelled definition
@@ -101,26 +106,29 @@ class MissingDefinition(dj.Manual):
101106
"""
102107

103108
with pytest.raises(NotImplementedError):
104-
schema_any(
105-
MissingDefinition, context=dict(MissingDefinition=MissingDefinition)
106-
)
109+
schema_any(MissingDefinition, context=dict(MissingDefinition=MissingDefinition))
110+
107111

108112
def test_empty_insert1(user):
109113
with pytest.raises(dj.DataJointError):
110114
user.insert1(())
111115

116+
112117
def test_empty_insert(user):
113118
with pytest.raises(dj.DataJointError):
114119
user.insert([()])
115120

121+
116122
def test_wrong_arguments_insert(user):
117123
with pytest.raises(dj.DataJointError):
118124
user.insert1(("First", "Second"))
119125

126+
120127
def test_wrong_insert_type(user):
121128
with pytest.raises(dj.DataJointError):
122129
user.insert1(3)
123130

131+
124132
def test_insert_select(subject):
125133
schema.TTest2.delete()
126134
schema.TTest2.insert(schema.TTest)
@@ -138,6 +146,7 @@ def test_insert_select(subject):
138146
subject.insert(elements, ignore_extra_fields=True)
139147
assert len(subject) == 2 * original_length
140148

149+
141150
def test_insert_pandas_roundtrip(schema_any):
142151
"""ensure fetched frames can be inserted"""
143152
schema.TTest2.delete()
@@ -149,6 +158,7 @@ def test_insert_pandas_roundtrip(schema_any):
149158
schema.TTest2.insert(df)
150159
assert len(schema.TTest2()) == n
151160

161+
152162
def test_insert_pandas_userframe(schema_any):
153163
"""
154164
ensure simple user-created frames (1 field, non-custom index)
@@ -163,12 +173,14 @@ def test_insert_pandas_userframe(schema_any):
163173
schema.TTest2.insert(df)
164174
assert len(schema.TTest2()) == n
165175

176+
166177
def test_insert_select_ignore_extra_fields0(test, test_extra):
167178
"""need ignore extra fields for insert select"""
168179
test_extra.insert1((test.fetch("key").max() + 1, 0, 0))
169180
with pytest.raises(dj.DataJointError):
170181
test.insert(test_extra)
171182

183+
172184
def test_insert_select_ignore_extra_fields1(test, test_extra):
173185
"""make sure extra fields works in insert select"""
174186
test_extra.delete()
@@ -177,11 +189,13 @@ def test_insert_select_ignore_extra_fields1(test, test_extra):
177189
test.insert(test_extra, ignore_extra_fields=True)
178190
assert keyno in test.fetch("key")
179191

192+
180193
def test_insert_select_ignore_extra_fields2(test_no_extra, test):
181194
"""make sure insert select still works when ignoring extra fields when there are none"""
182195
test_no_extra.delete()
183196
test_no_extra.insert(test, ignore_extra_fields=True)
184197

198+
185199
def test_insert_select_ignore_extra_fields3(test, test_no_extra, test_extra):
186200
"""make sure insert select works for from query result"""
187201
# Recreate table state from previous tests
@@ -195,12 +209,14 @@ def test_insert_select_ignore_extra_fields3(test, test_no_extra, test_extra):
195209
keystr = str(test_extra.fetch("key").max())
196210
test_no_extra.insert((test_extra & "`key`=" + keystr), ignore_extra_fields=True)
197211

212+
198213
def test_skip_duplicates(test_no_extra, test):
199214
"""test that skip_duplicates works when inserting from another table"""
200215
test_no_extra.delete()
201216
test_no_extra.insert(test, ignore_extra_fields=True, skip_duplicates=True)
202217
test_no_extra.insert(test, ignore_extra_fields=True, skip_duplicates=True)
203218

219+
204220
def test_replace(subject):
205221
"""
206222
Test replacing or ignoring duplicate entries
@@ -214,14 +230,13 @@ def test_replace(subject):
214230
dict(key, real_id=7, date_of_birth=date, subject_notes=""),
215231
skip_duplicates=True,
216232
)
217-
assert date != str(
218-
(subject & key).fetch1("date_of_birth")
219-
), "inappropriate replace"
233+
assert date != str((subject & key).fetch1("date_of_birth")), "inappropriate replace"
220234
subject.insert1(
221235
dict(key, real_id=7, date_of_birth=date, subject_notes=""), replace=True
222236
)
223237
assert date == str((subject & key).fetch1("date_of_birth")), "replace failed"
224238

239+
225240
def test_delete_quick(subject):
226241
"""Tests quick deletion"""
227242
tmp = np.array(
@@ -232,13 +247,12 @@ def test_delete_quick(subject):
232247
dtype=subject.heading.as_dtype,
233248
)
234249
subject.insert(tmp)
235-
s = subject & (
236-
"subject_id in (%s)" % ",".join(str(r) for r in tmp["subject_id"])
237-
)
250+
s = subject & ("subject_id in (%s)" % ",".join(str(r) for r in tmp["subject_id"]))
238251
assert len(s) == 2, "insert did not work."
239252
s.delete_quick()
240253
assert len(s) == 0, "delete did not work."
241254

255+
242256
def test_skip_duplicate(subject):
243257
"""Tests if duplicates are properly skipped."""
244258
tmp = np.array(
@@ -258,6 +272,7 @@ def test_skip_duplicate(subject):
258272
)
259273
subject.insert(tmp, skip_duplicates=True)
260274

275+
261276
def test_not_skip_duplicate(subject):
262277
"""Tests if duplicates are not skipped."""
263278
tmp = np.array(
@@ -271,18 +286,21 @@ def test_not_skip_duplicate(subject):
271286
with pytest.raises(dj.errors.DuplicateError):
272287
subject.insert(tmp, skip_duplicates=False)
273288

289+
274290
def test_no_error_suppression(test):
275291
"""skip_duplicates=True should not suppress other errors"""
276292
with pytest.raises(dj.errors.MissingAttributeError):
277293
test.insert([dict(key=100)], skip_duplicates=True)
278294

295+
279296
def test_blob_insert(img):
280297
"""Tests inserting and retrieving blobs."""
281298
X = np.random.randn(20, 10)
282299
img.insert1((1, X))
283300
Y = img.fetch()[0]["img"]
284301
assert np.all(X == Y), "Inserted and retrieved image are not identical"
285302

303+
286304
def test_drop(trash):
287305
"""Tests dropping tables"""
288306
dj.config["safemode"] = True
@@ -296,6 +314,7 @@ def test_drop(trash):
296314
finally:
297315
dj.config["safemode"] = False
298316

317+
299318
def test_table_regexp(schema_any):
300319
"""Test whether table names are matched by regular expressions"""
301320

@@ -315,10 +334,12 @@ def relation_selector(attr):
315334
tier.tier_regexp, rel.table_name
316335
), "Regular expression matches for {name} but should not".format(name=name)
317336

337+
318338
def test_table_size(experiment):
319339
"""test getting the size of the table and its indices in bytes"""
320340
number_of_bytes = experiment.size_on_disk
321341
assert isinstance(number_of_bytes, int) and number_of_bytes > 100
322342

343+
323344
def test_repr_html(ephys):
324345
assert ephys._repr_html_().strip().startswith("<style")

0 commit comments

Comments
 (0)