@@ -216,3 +216,37 @@ def test_keyattr_dynamic_inheritance_on_casting(self) -> None:
216216 d = benedict (keyattr_dynamic = False )
217217 c = benedict (d )
218218 self .assertFalse (c .keyattr_dynamic )
219+
220+ def test_dir_with_keyattr_enabled (self ) -> None :
221+ d = benedict ({"a" : 1 , "b" : 2 }, keyattr_enabled = True )
222+ result = dir (d )
223+ self .assertIn ("a" , result )
224+ self .assertIn ("b" , result )
225+
226+ def test_dir_with_keyattr_disabled (self ) -> None :
227+ d = benedict ({"a" : 1 , "b" : 2 }, keyattr_enabled = False )
228+ result = dir (d )
229+ self .assertNotIn ("a" , result )
230+ self .assertNotIn ("b" , result )
231+
232+ def test_dir_with_nested_keys (self ) -> None :
233+ d = benedict ({"a" : {"b" : {"c" : 1 }}}, keyattr_enabled = True )
234+ self .assertIn ("a" , dir (d ))
235+ self .assertIn ("b" , dir (d .a ))
236+ self .assertIn ("c" , dir (d .a .b ))
237+
238+ def test_ipython_key_completions (self ) -> None :
239+ d = benedict ({"a" : 1 , "b" : 2 })
240+ self .assertEqual (sorted (d ._ipython_key_completions_ ()), ["a" , "b" ])
241+
242+ def test_ipython_key_completions_with_nested_keys (self ) -> None :
243+ d = benedict ({"a" : {"b" : {"c" : 1 }}})
244+ self .assertEqual (d ._ipython_key_completions_ (), ["a" ])
245+ self .assertEqual (d .a ._ipython_key_completions_ (), ["b" ])
246+ self .assertEqual (d .a .b ._ipython_key_completions_ (), ["c" ])
247+
248+ def test_dir_skips_non_string_keys (self ) -> None :
249+ d = benedict ({1 : "a" , "b" : 2 }, keyattr_enabled = True )
250+ result = dir (d )
251+ self .assertIn ("b" , result )
252+ self .assertNotIn (1 , result )
0 commit comments