diff options
Diffstat (limited to 'Lib/test/test_module.py')
-rw-r--r-- | Lib/test/test_module.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py index 1230293..9da3536 100644 --- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -30,6 +30,22 @@ class ModuleTests(unittest.TestCase): pass self.assertEqual(foo.__doc__, ModuleType.__doc__) + def test_unintialized_missing_getattr(self): + # Issue 8297 + # test the text in the AttributeError of an uninitialized module + foo = ModuleType.__new__(ModuleType) + self.assertRaisesRegex( + AttributeError, "module has no attribute 'not_here'", + getattr, foo, "not_here") + + def test_missing_getattr(self): + # Issue 8297 + # test the text in the AttributeError + foo = ModuleType("foo") + self.assertRaisesRegex( + AttributeError, "module 'foo' has no attribute 'not_here'", + getattr, foo, "not_here") + def test_no_docstring(self): # Regularly initialized module, no docstring foo = ModuleType("foo") @@ -211,6 +227,14 @@ a = A(destroyed)""" b"len = len", b"shutil.rmtree = rmtree"}) + def test_descriptor_errors_propogate(self): + class Descr: + def __get__(self, o, t): + raise RuntimeError + class M(ModuleType): + melon = Descr() + self.assertRaises(RuntimeError, getattr, M("mymod"), "melon") + # frozen and namespace module reprs are tested in importlib. |