()
| 40 | |
| 41 | |
| 42 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…