]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103193: Improve `getattr_static` test coverage (#104286)
authorAlex Waygood <Alex.Waygood@Gmail.com>
Mon, 8 May 2023 14:18:36 +0000 (15:18 +0100)
committerGitHub <noreply@github.com>
Mon, 8 May 2023 14:18:36 +0000 (15:18 +0100)
Lib/test/test_inspect.py

index dd0325a43e0f588c07037478c587ea2b4866d262..d2b2f3171e785dbc67c59c6f0e283785206dd62a 100644 (file)
@@ -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):