@@ -145,3 +145,33 @@ 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 there is an atempt to convert it 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+ com .matches (2 ,"d[" , local )
162+ self .assertSetEqual (com .matches (2 ,"d[" , local ),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+ self .assertSetEqual (com .matches (2 ,"d[" , local ),set ())
168+
169+ def test_empty_set_returned_when_not_dict_type (self ):
170+ com = autocomplete .DictKeyCompletion ()
171+ local = {'l' :["ab" , "cd" ],}
172+ self .assertSetEqual (com .matches (2 ,"l[" , local ),set ())
173+
174+ def test_obj_that_does_not_allow_conversion_to_bool (self ):
175+ com = autocomplete .DictKeyCompletion ()
176+ local = {'mNumPy' :MockNumPy (),}
177+ self .assertSetEqual (com .matches (7 ,"mNumPy[" , local ), set ())
0 commit comments