MCPcopy Index your code
hub / github.com/ipython/ipython / test_misbehaving_object_without_trait_names

Function test_misbehaving_object_without_trait_names

tests/test_dir2.py:42–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40
41
42def test_misbehaving_object_without_trait_names():
43 # dir2 shouldn't raise even when objects are dumb and raise
44 # something other than AttribteErrors on bad getattr.
45
46 class MisbehavingGetattr:
47 def __getattr__(self, attr):
48 raise KeyError("I should be caught")
49
50 def some_method(self):
51 return True
52
53 class SillierWithDir(MisbehavingGetattr):
54 def __dir__(self):
55 return ["some_method"]
56
57 for bad_klass in (MisbehavingGetattr, SillierWithDir):
58 obj = bad_klass()
59
60 assert obj.some_method()
61
62 with pytest.raises(KeyError):
63 obj.other_method()
64
65 res = dir2(obj)
66 assert "some_method" in res

Callers

nothing calls this directly

Calls 2

dir2Function · 0.90
some_methodMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…