@@ -77,21 +77,26 @@ def test_contents(user, subject):
77
77
u = subject .fetch (order_by = ["subject_id" ])
78
78
assert list (u ["subject_id" ]) == sorted ([s [0 ] for s in subject .contents ])
79
79
80
+
80
81
def test_misnamed_attribute1 (user ):
81
82
with pytest .raises (dj .DataJointError ):
82
83
user .insert ([dict (username = "Bob" ), dict (user = "Alice" )])
83
84
85
+
84
86
def test_misnamed_attribute2 (user ):
85
87
with pytest .raises (KeyError ):
86
88
user .insert1 (dict (user = "Bob" ))
87
89
90
+
88
91
def test_extra_attribute1 (user ):
89
92
with pytest .raises (KeyError ):
90
93
user .insert1 (dict (username = "Robert" , spouse = "Alice" ))
91
94
95
+
92
96
def test_extra_attribute2 (user ):
93
97
user .insert1 (dict (username = "Robert" , spouse = "Alice" ), ignore_extra_fields = True )
94
98
99
+
95
100
def test_missing_definition (schema_any ):
96
101
class MissingDefinition (dj .Manual ):
97
102
definitions = """ # misspelled definition
@@ -101,26 +106,29 @@ class MissingDefinition(dj.Manual):
101
106
"""
102
107
103
108
with pytest .raises (NotImplementedError ):
104
- schema_any (
105
- MissingDefinition , context = dict (MissingDefinition = MissingDefinition )
106
- )
109
+ schema_any (MissingDefinition , context = dict (MissingDefinition = MissingDefinition ))
110
+
107
111
108
112
def test_empty_insert1 (user ):
109
113
with pytest .raises (dj .DataJointError ):
110
114
user .insert1 (())
111
115
116
+
112
117
def test_empty_insert (user ):
113
118
with pytest .raises (dj .DataJointError ):
114
119
user .insert ([()])
115
120
121
+
116
122
def test_wrong_arguments_insert (user ):
117
123
with pytest .raises (dj .DataJointError ):
118
124
user .insert1 (("First" , "Second" ))
119
125
126
+
120
127
def test_wrong_insert_type (user ):
121
128
with pytest .raises (dj .DataJointError ):
122
129
user .insert1 (3 )
123
130
131
+
124
132
def test_insert_select (subject ):
125
133
schema .TTest2 .delete ()
126
134
schema .TTest2 .insert (schema .TTest )
@@ -138,6 +146,7 @@ def test_insert_select(subject):
138
146
subject .insert (elements , ignore_extra_fields = True )
139
147
assert len (subject ) == 2 * original_length
140
148
149
+
141
150
def test_insert_pandas_roundtrip (schema_any ):
142
151
"""ensure fetched frames can be inserted"""
143
152
schema .TTest2 .delete ()
@@ -149,6 +158,7 @@ def test_insert_pandas_roundtrip(schema_any):
149
158
schema .TTest2 .insert (df )
150
159
assert len (schema .TTest2 ()) == n
151
160
161
+
152
162
def test_insert_pandas_userframe (schema_any ):
153
163
"""
154
164
ensure simple user-created frames (1 field, non-custom index)
@@ -163,12 +173,14 @@ def test_insert_pandas_userframe(schema_any):
163
173
schema .TTest2 .insert (df )
164
174
assert len (schema .TTest2 ()) == n
165
175
176
+
166
177
def test_insert_select_ignore_extra_fields0 (test , test_extra ):
167
178
"""need ignore extra fields for insert select"""
168
179
test_extra .insert1 ((test .fetch ("key" ).max () + 1 , 0 , 0 ))
169
180
with pytest .raises (dj .DataJointError ):
170
181
test .insert (test_extra )
171
182
183
+
172
184
def test_insert_select_ignore_extra_fields1 (test , test_extra ):
173
185
"""make sure extra fields works in insert select"""
174
186
test_extra .delete ()
@@ -177,11 +189,13 @@ def test_insert_select_ignore_extra_fields1(test, test_extra):
177
189
test .insert (test_extra , ignore_extra_fields = True )
178
190
assert keyno in test .fetch ("key" )
179
191
192
+
180
193
def test_insert_select_ignore_extra_fields2 (test_no_extra , test ):
181
194
"""make sure insert select still works when ignoring extra fields when there are none"""
182
195
test_no_extra .delete ()
183
196
test_no_extra .insert (test , ignore_extra_fields = True )
184
197
198
+
185
199
def test_insert_select_ignore_extra_fields3 (test , test_no_extra , test_extra ):
186
200
"""make sure insert select works for from query result"""
187
201
# Recreate table state from previous tests
@@ -195,12 +209,14 @@ def test_insert_select_ignore_extra_fields3(test, test_no_extra, test_extra):
195
209
keystr = str (test_extra .fetch ("key" ).max ())
196
210
test_no_extra .insert ((test_extra & "`key`=" + keystr ), ignore_extra_fields = True )
197
211
212
+
198
213
def test_skip_duplicates (test_no_extra , test ):
199
214
"""test that skip_duplicates works when inserting from another table"""
200
215
test_no_extra .delete ()
201
216
test_no_extra .insert (test , ignore_extra_fields = True , skip_duplicates = True )
202
217
test_no_extra .insert (test , ignore_extra_fields = True , skip_duplicates = True )
203
218
219
+
204
220
def test_replace (subject ):
205
221
"""
206
222
Test replacing or ignoring duplicate entries
@@ -214,14 +230,13 @@ def test_replace(subject):
214
230
dict (key , real_id = 7 , date_of_birth = date , subject_notes = "" ),
215
231
skip_duplicates = True ,
216
232
)
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"
220
234
subject .insert1 (
221
235
dict (key , real_id = 7 , date_of_birth = date , subject_notes = "" ), replace = True
222
236
)
223
237
assert date == str ((subject & key ).fetch1 ("date_of_birth" )), "replace failed"
224
238
239
+
225
240
def test_delete_quick (subject ):
226
241
"""Tests quick deletion"""
227
242
tmp = np .array (
@@ -232,13 +247,12 @@ def test_delete_quick(subject):
232
247
dtype = subject .heading .as_dtype ,
233
248
)
234
249
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" ]))
238
251
assert len (s ) == 2 , "insert did not work."
239
252
s .delete_quick ()
240
253
assert len (s ) == 0 , "delete did not work."
241
254
255
+
242
256
def test_skip_duplicate (subject ):
243
257
"""Tests if duplicates are properly skipped."""
244
258
tmp = np .array (
@@ -258,6 +272,7 @@ def test_skip_duplicate(subject):
258
272
)
259
273
subject .insert (tmp , skip_duplicates = True )
260
274
275
+
261
276
def test_not_skip_duplicate (subject ):
262
277
"""Tests if duplicates are not skipped."""
263
278
tmp = np .array (
@@ -271,18 +286,21 @@ def test_not_skip_duplicate(subject):
271
286
with pytest .raises (dj .errors .DuplicateError ):
272
287
subject .insert (tmp , skip_duplicates = False )
273
288
289
+
274
290
def test_no_error_suppression (test ):
275
291
"""skip_duplicates=True should not suppress other errors"""
276
292
with pytest .raises (dj .errors .MissingAttributeError ):
277
293
test .insert ([dict (key = 100 )], skip_duplicates = True )
278
294
295
+
279
296
def test_blob_insert (img ):
280
297
"""Tests inserting and retrieving blobs."""
281
298
X = np .random .randn (20 , 10 )
282
299
img .insert1 ((1 , X ))
283
300
Y = img .fetch ()[0 ]["img" ]
284
301
assert np .all (X == Y ), "Inserted and retrieved image are not identical"
285
302
303
+
286
304
def test_drop (trash ):
287
305
"""Tests dropping tables"""
288
306
dj .config ["safemode" ] = True
@@ -296,6 +314,7 @@ def test_drop(trash):
296
314
finally :
297
315
dj .config ["safemode" ] = False
298
316
317
+
299
318
def test_table_regexp (schema_any ):
300
319
"""Test whether table names are matched by regular expressions"""
301
320
@@ -315,10 +334,12 @@ def relation_selector(attr):
315
334
tier .tier_regexp , rel .table_name
316
335
), "Regular expression matches for {name} but should not" .format (name = name )
317
336
337
+
318
338
def test_table_size (experiment ):
319
339
"""test getting the size of the table and its indices in bytes"""
320
340
number_of_bytes = experiment .size_on_disk
321
341
assert isinstance (number_of_bytes , int ) and number_of_bytes > 100
322
342
343
+
323
344
def test_repr_html (ephys ):
324
345
assert ephys ._repr_html_ ().strip ().startswith ("<style" )
0 commit comments