mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-103193: Improve getattr_static
test coverage (#104286)
This commit is contained in:
parent
d513ddee94
commit
921185ed05
1 changed files with 29 additions and 0 deletions
|
@ -2187,6 +2187,35 @@ class TestGetattrStatic(unittest.TestCase):
|
|||
inspect.getattr_static(Thing, "spam")
|
||||
self.assertFalse(Thing.executed)
|
||||
|
||||
def test_custom___getattr__(self):
|
||||
test = self
|
||||
test.called = False
|
||||
|
||||
class Foo:
|
||||
def __getattr__(self, attr):
|
||||
test.called = True
|
||||
return {}
|
||||
|
||||
with self.assertRaises(AttributeError):
|
||||
inspect.getattr_static(Foo(), 'whatever')
|
||||
|
||||
self.assertFalse(test.called)
|
||||
|
||||
def test_custom___getattribute__(self):
|
||||
test = self
|
||||
test.called = False
|
||||
|
||||
class Foo:
|
||||
def __getattribute__(self, attr):
|
||||
test.called = True
|
||||
return {}
|
||||
|
||||
with self.assertRaises(AttributeError):
|
||||
inspect.getattr_static(Foo(), 'really_could_be_anything')
|
||||
|
||||
self.assertFalse(test.called)
|
||||
|
||||
|
||||
class TestGetGeneratorState(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue