@@ -145,3 +145,38 @@ def test_formatting_takes_just_last_part(self):
145145 self .assertEqual (self .completer .format ('/hello/there/' ), 'there/' )
146146 self .assertEqual (self .completer .format ('/hello/there' ), 'there' )
147147
148+ class MockNumPy (object ):
149+ """
150+ This is a mock numpy object that raises an error when it is trying to be converted to a boolean.
151+ """
152+ def __nonzero__ (self ):
153+ raise ValueError ("The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" )
154+
155+
156+ class TestDictKeyCompletion (unittest .TestCase ):
157+
158+ def test_set_of_keys_returned_when_matches_found (self ):
159+ com = autocomplete .DictKeyCompletion ()
160+ local = {'d' :{"ab" :1 , "cd" :2 },}
161+ result = com .matches (2 ,"d[" , local )
162+ self .assertSetEqual (result ,set (["'ab'" ,"'cd'" ]))
163+
164+ def test_empty_set_returned_when_eval_error (self ):
165+ com = autocomplete .DictKeyCompletion ()
166+ local = {'e' :{"ab" :1 , "cd" :2 },}
167+ result = com .matches (2 ,"d[" , local )
168+ self .assertSetEqual (result ,set ())
169+
170+ def test_empty_set_returned_when_not_dict_type (self ):
171+ com = autocomplete .DictKeyCompletion ()
172+ local = {'l' :["ab" , "cd" ],}
173+ result = com .matches (2 ,"l[" , local )
174+ self .assertSetEqual (result ,set ())
175+
176+ def test_obj_that_does_not_allow_bool_tests (self ):
177+ com = autocomplete .DictKeyCompletion ()
178+ local = {'mNumPy' :MockNumPy (),}
179+ try :
180+ com .matches (7 ,"mNumPy[" , local )
181+ except ValueError :
182+ raise AssertionError ("Dict key completion raised value error." )
0 commit comments