diff options
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r-- | Lib/test/test_importlib/builtin/test_loader.py | 72 | ||||
-rw-r--r-- | Lib/test/test_importlib/extension/test_loader.py | 65 |
2 files changed, 0 insertions, 137 deletions
diff --git a/Lib/test/test_importlib/builtin/test_loader.py b/Lib/test/test_importlib/builtin/test_loader.py index 8e12813..a636f77 100644 --- a/Lib/test/test_importlib/builtin/test_loader.py +++ b/Lib/test/test_importlib/builtin/test_loader.py @@ -9,78 +9,6 @@ import types import unittest -class ExecModTests(abc.LoaderTests): - - """Test exec_module() for built-in modules.""" - - @classmethod - def setUpClass(cls): - cls.verification = {'__name__': 'errno', '__package__': '', - '__loader__': cls.machinery.BuiltinImporter} - - def verify(self, module): - """Verify that the module matches against what it should have.""" - self.assertIsInstance(module, types.ModuleType) - for attr, value in self.verification.items(): - self.assertEqual(getattr(module, attr), value) - self.assertIn(module.__name__, sys.modules) - self.assertTrue(hasattr(module, '__spec__')) - self.assertEqual(module.__spec__.origin, 'built-in') - - def load_spec(self, name): - spec = self.machinery.ModuleSpec(name, self.machinery.BuiltinImporter, - origin='built-in') - module = types.ModuleType(name) - module.__spec__ = spec - self.machinery.BuiltinImporter.exec_module(module) - # Strictly not what exec_module() is supposed to do, but since - # _imp.init_builtin() does this we can't get around it. - return sys.modules[name] - - def test_module(self): - # Common case. - with util.uncache(builtin_util.NAME): - module = self.load_spec(builtin_util.NAME) - self.verify(module) - self.assertIn('built-in', str(module)) - - # Built-in modules cannot be a package. - test_package = None - - # Built-in modules cannot be a package. - test_lacking_parent = None - - # Not way to force an import failure. - test_state_after_failure = None - - def test_unloadable(self): - name = 'dssdsdfff' - assert name not in sys.builtin_module_names - with self.assertRaises(ImportError) as cm: - self.load_spec(name) - self.assertEqual(cm.exception.name, name) - - def test_already_imported(self): - # Using the name of a module already imported but not a built-in should - # still fail. - module_name = 'builtin_reload_test' - assert module_name not in sys.builtin_module_names - with util.uncache(module_name): - module = types.ModuleType(module_name) - spec = self.machinery.ModuleSpec(module_name, - self.machinery.BuiltinImporter, - origin='built-in') - module.__spec__ = spec - sys.modules[module_name] = module - with self.assertRaises(ImportError) as cm: - self.machinery.BuiltinImporter.exec_module(module) - self.assertEqual(cm.exception.name, module_name) - - -Frozen_ExecModTests, Source_ExecModTests = util.test_both(ExecModTests, - machinery=[frozen_machinery, source_machinery]) - - class LoaderTests(abc.LoaderTests): """Test load_module() for built-in modules.""" diff --git a/Lib/test/test_importlib/extension/test_loader.py b/Lib/test/test_importlib/extension/test_loader.py index 58bd09f..d04dff5 100644 --- a/Lib/test/test_importlib/extension/test_loader.py +++ b/Lib/test/test_importlib/extension/test_loader.py @@ -10,71 +10,6 @@ import types import unittest -class ExecModuleTests(abc.LoaderTests): - - """Test load_module() for extension modules.""" - - def setUp(self): - self.loader = self.machinery.ExtensionFileLoader(ext_util.NAME, - ext_util.FILEPATH) - - def exec_module(self, fullname): - module = types.ModuleType(fullname) - module.__spec__ = self.machinery.ModuleSpec(fullname, self.loader) - self.loader.exec_module(module) - return sys.modules[fullname] - - def test_exec_module_API(self): - with self.assertRaises(ImportError): - self.exec_module('XXX') - - - def test_module(self): - with util.uncache(ext_util.NAME): - module = self.exec_module(ext_util.NAME) - for attr, value in [('__name__', ext_util.NAME), - ('__file__', ext_util.FILEPATH), - ('__package__', '')]: - given = getattr(module, attr) - self.assertEqual(given, value, - '{}: {!r} != {!r}'.format(attr, given, value)) - self.assertIn(ext_util.NAME, sys.modules) - self.assertIsInstance(module.__loader__, - self.machinery.ExtensionFileLoader) - - # No extension module as __init__ available for testing. - test_package = None - - # No extension module in a package available for testing. - test_lacking_parent = None - - def test_module_reuse(self): - with util.uncache(ext_util.NAME): - module1 = self.exec_module(ext_util.NAME) - module2 = self.exec_module(ext_util.NAME) - self.assertIs(module1, module2) - - def test_state_after_failure(self): - # No easy way to trigger a failure after a successful import. - pass - - def test_unloadable(self): - name = 'asdfjkl;' - with self.assertRaises(ImportError) as cm: - self.exec_module(name) - self.assertEqual(cm.exception.name, name) - - def test_is_package(self): - self.assertFalse(self.loader.is_package(ext_util.NAME)) - for suffix in self.machinery.EXTENSION_SUFFIXES: - path = os.path.join('some', 'path', 'pkg', '__init__' + suffix) - loader = self.machinery.ExtensionFileLoader('pkg', path) - self.assertTrue(loader.is_package('pkg')) - -Frozen_ExecModuleTests, Source_ExecModuleTests = util.test_both( - ExecModuleTests, machinery=machinery) - - class LoaderTests(abc.LoaderTests): """Test load_module() for extension modules.""" |