[3.11] gh-103193: Improve `getattr_static` test coverage (GH-104286) (#104290)

gh-103193: Improve `getattr_static` test coverage (GH-104286)
(cherry picked from commit 921185ed05)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-05-08 07:44:10 -07:00 committed by GitHub
parent 499b79d0b9
commit d54f6441ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 0 deletions

View File

@ -2106,6 +2106,35 @@ class Thing(metaclass=Meta):
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):