@@ -187,7 +187,7 @@ def test_limit_warning(self):
187187
188188 def test_len (self ):
189189 """Tests __len__"""
190- assert_true (len (self .lang .fetch ()) == len (self .lang ), '__len__ is not behaving properly' )
190+ assert_equal (len (self .lang .fetch ()), len (self .lang ), '__len__ is not behaving properly' )
191191
192192 @raises (dj .DataJointError )
193193 def test_fetch1_step2 (self ):
@@ -222,31 +222,33 @@ def test_nullable_numbers(self):
222222
223223 def test_fetch_format (self ):
224224 """test fetch_format='frame'"""
225- dj .config ['fetch_format' ] = 'frame'
226- # test if lists are both dicts
227- list1 = sorted (self .subject .proj ().fetch (as_dict = True ), key = itemgetter ('subject_id' ))
228- list2 = sorted (self .subject .fetch (dj .key ), key = itemgetter ('subject_id' ))
229- for l1 , l2 in zip (list1 , list2 ):
230- assert_dict_equal (l1 , l2 , 'Primary key is not returned correctly' )
231-
232- # tests if pandas dataframe
233- tmp = self .subject .fetch (order_by = 'subject_id' )
234- assert_true (isinstance (tmp , pandas .DataFrame ))
235- tmp = tmp .to_records ()
236-
237- subject_notes , key , real_id = self .subject .fetch ('subject_notes' , dj .key , 'real_id' )
238-
239- np .testing .assert_array_equal (sorted (subject_notes ), sorted (tmp ['subject_notes' ]))
240- np .testing .assert_array_equal (sorted (real_id ), sorted (tmp ['real_id' ]))
241- list1 = sorted (key , key = itemgetter ('subject_id' ))
242- for l1 , l2 in zip (list1 , list2 ):
243- assert_dict_equal (l1 , l2 , 'Primary key is not returned correctly' )
244-
245- # test pandas with fetch1
246- # k = (self.subject & 'subject_id=10').fetch1('KEY')
247-
248- # revert configuration of fetch format
249- dj .config ['fetch_format' ] = 'array'
225+ with dj .config (fetch_format = 'frame' ):
226+ # test if lists are both dicts
227+ list1 = sorted (self .subject .proj ().fetch (as_dict = True ), key = itemgetter ('subject_id' ))
228+ list2 = sorted (self .subject .fetch (dj .key ), key = itemgetter ('subject_id' ))
229+ for l1 , l2 in zip (list1 , list2 ):
230+ assert_dict_equal (l1 , l2 , 'Primary key is not returned correctly' )
231+
232+ # tests if pandas dataframe
233+ tmp = self .subject .fetch (order_by = 'subject_id' )
234+ assert_true (isinstance (tmp , pandas .DataFrame ))
235+ tmp = tmp .to_records ()
236+
237+ subject_notes , key , real_id = self .subject .fetch ('subject_notes' , dj .key , 'real_id' )
238+
239+ np .testing .assert_array_equal (sorted (subject_notes ), sorted (tmp ['subject_notes' ]))
240+ np .testing .assert_array_equal (sorted (real_id ), sorted (tmp ['real_id' ]))
241+ list1 = sorted (key , key = itemgetter ('subject_id' ))
242+ for l1 , l2 in zip (list1 , list2 ):
243+ assert_dict_equal (l1 , l2 , 'Primary key is not returned correctly' )
244+
245+ def test_key_fetch1 (self ):
246+ """test KEY fetch1 - issue #976"""
247+ with dj .config (fetch_format = "array" ):
248+ k1 = (self .subject & 'subject_id=10' ).fetch1 ('KEY' )
249+ with dj .config (fetch_format = "frame" ):
250+ k2 = (self .subject & 'subject_id=10' ).fetch1 ('KEY' )
251+ assert_equal (k1 , k2 )
250252
251253 def test_same_secondary_attribute (self ):
252254 print (schema .Child * schema .Parent ().proj ())
0 commit comments