diff options
Diffstat (limited to 'Lib/test/test_module.py')
-rw-r--r-- | Lib/test/test_module.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py index 1230293..48ab0b4 100644 --- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -1,8 +1,8 @@ # Test the module type import unittest import weakref -from test.support import run_unittest, gc_collect -from test.script_helper import assert_python_ok +from test.support import gc_collect +from test.support.script_helper import assert_python_ok import sys ModuleType = type(sys) @@ -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,12 +227,16 @@ a = A(destroyed)""" b"len = len", b"shutil.rmtree = rmtree"}) - # frozen and namespace module reprs are tested in importlib. - + 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") -def test_main(): - run_unittest(ModuleTests) + # frozen and namespace module reprs are tested in importlib. if __name__ == '__main__': - test_main() + unittest.main() |