summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Waygood <Alex.Waygood@Gmail.com>2023-05-08 14:18:36 (GMT)
committerGitHub <noreply@github.com>2023-05-08 14:18:36 (GMT)
commit921185ed050efbca2f0adeab79f676b7f8cc3660 (patch)
tree187377653326d7dd2a31492a374ecfd45f5c6bc1
parentd513ddee94a05783b98f2b55f8fc0a4efbb9be82 (diff)
downloadcpython-921185ed050efbca2f0adeab79f676b7f8cc3660.zip
cpython-921185ed050efbca2f0adeab79f676b7f8cc3660.tar.gz
cpython-921185ed050efbca2f0adeab79f676b7f8cc3660.tar.bz2
gh-103193: Improve `getattr_static` test coverage (#104286)
-rw-r--r--Lib/test/test_inspect.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index dd0325a..d2b2f31 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -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):