[Python-checkins] cpython: Issue #17177: stop using imp in test_importlib

brett.cannon python-checkins at python.org
Sun Jun 16 00:39:30 CEST 2013


http://hg.python.org/cpython/rev/5e8b377942f7
changeset:   84159:5e8b377942f7
user:        Brett Cannon <brett at python.org>
date:        Sat Jun 15 18:39:21 2013 -0400
summary:
  Issue #17177: stop using imp in test_importlib

files:
  Lib/test/test_importlib/extension/test_case_sensitivity.py |   9 +-
  Lib/test/test_importlib/extension/test_path_hook.py        |   1 -
  Lib/test/test_importlib/extension/util.py                  |   1 -
  Lib/test/test_importlib/frozen/test_loader.py              |  10 +-
  Lib/test/test_importlib/import_/test___loader__.py         |   6 +-
  Lib/test/test_importlib/import_/test_api.py                |   5 +-
  Lib/test/test_importlib/import_/test_fromlist.py           |   1 -
  Lib/test/test_importlib/source/test_case_sensitivity.py    |   6 +-
  Lib/test/test_importlib/source/test_file_loader.py         |  19 ++-
  Lib/test/test_importlib/source/test_finder.py              |   1 -
  Lib/test/test_importlib/source/test_path_hook.py           |   1 -
  Lib/test/test_importlib/source/util.py                     |   1 -
  Lib/test/test_importlib/test_abc.py                        |  49 +++++----
  Lib/test/test_importlib/test_api.py                        |  10 +-
  Lib/test/test_importlib/test_util.py                       |  30 +++---
  Lib/test/test_importlib/util.py                            |   4 +-
  16 files changed, 78 insertions(+), 76 deletions(-)


diff --git a/Lib/test/test_importlib/extension/test_case_sensitivity.py b/Lib/test/test_importlib/extension/test_case_sensitivity.py
--- a/Lib/test/test_importlib/extension/test_case_sensitivity.py
+++ b/Lib/test/test_importlib/extension/test_case_sensitivity.py
@@ -1,8 +1,9 @@
-import imp
 import sys
 from test import support
 import unittest
+
 from importlib import _bootstrap
+from importlib import machinery
 from .. import util
 from . import util as ext_util
 
@@ -14,9 +15,9 @@
         good_name = ext_util.NAME
         bad_name = good_name.upper()
         assert good_name != bad_name
-        finder = _bootstrap.FileFinder(ext_util.PATH,
-                                        (_bootstrap.ExtensionFileLoader,
-                                         _bootstrap.EXTENSION_SUFFIXES))
+        finder = machinery.FileFinder(ext_util.PATH,
+                                        (machinery.ExtensionFileLoader,
+                                         machinery.EXTENSION_SUFFIXES))
         return finder.find_module(bad_name)
 
     def test_case_sensitive(self):
diff --git a/Lib/test/test_importlib/extension/test_path_hook.py b/Lib/test/test_importlib/extension/test_path_hook.py
--- a/Lib/test/test_importlib/extension/test_path_hook.py
+++ b/Lib/test/test_importlib/extension/test_path_hook.py
@@ -2,7 +2,6 @@
 from . import util
 
 import collections
-import imp
 import sys
 import unittest
 
diff --git a/Lib/test/test_importlib/extension/util.py b/Lib/test/test_importlib/extension/util.py
--- a/Lib/test/test_importlib/extension/util.py
+++ b/Lib/test/test_importlib/extension/util.py
@@ -1,4 +1,3 @@
-import imp
 from importlib import machinery
 import os
 import sys
diff --git a/Lib/test/test_importlib/frozen/test_loader.py b/Lib/test/test_importlib/frozen/test_loader.py
--- a/Lib/test/test_importlib/frozen/test_loader.py
+++ b/Lib/test/test_importlib/frozen/test_loader.py
@@ -1,9 +1,11 @@
-from importlib import machinery
-import imp
-import unittest
 from .. import abc
 from .. import util
+
+from importlib import machinery
+import unittest
 from test.support import captured_stdout
+import types
+
 
 class LoaderTests(abc.LoaderTests):
 
@@ -85,7 +87,7 @@
         name = '__hello__'
         with captured_stdout() as stdout:
             code = machinery.FrozenImporter.get_code(name)
-            mod = imp.new_module(name)
+            mod = types.ModuleType(name)
             exec(code, mod.__dict__)
             self.assertTrue(hasattr(mod, 'initialized'))
             self.assertEqual(stdout.getvalue(), 'Hello world!\n')
diff --git a/Lib/test/test_importlib/import_/test___loader__.py b/Lib/test/test_importlib/import_/test___loader__.py
--- a/Lib/test/test_importlib/import_/test___loader__.py
+++ b/Lib/test/test_importlib/import_/test___loader__.py
@@ -1,5 +1,5 @@
-import imp
 import sys
+import types
 import unittest
 
 from .. import util
@@ -19,7 +19,7 @@
 class LoaderAttributeTests(unittest.TestCase):
 
     def test___loader___missing(self):
-        module = imp.new_module('blah')
+        module = types.ModuleType('blah')
         try:
             del module.__loader__
         except AttributeError:
@@ -31,7 +31,7 @@
         self.assertEqual(loader, module.__loader__)
 
     def test___loader___is_None(self):
-        module = imp.new_module('blah')
+        module = types.ModuleType('blah')
         module.__loader__ = None
         loader = LoaderMock()
         loader.module = module
diff --git a/Lib/test/test_importlib/import_/test_api.py b/Lib/test/test_importlib/import_/test_api.py
--- a/Lib/test/test_importlib/import_/test_api.py
+++ b/Lib/test/test_importlib/import_/test_api.py
@@ -2,6 +2,7 @@
 from . import util
 import imp
 import sys
+import types
 import unittest
 
 
@@ -48,7 +49,7 @@
     def test_nonexistent_fromlist_entry(self):
         # If something in fromlist doesn't exist, that's okay.
         # issue15715
-        mod = imp.new_module('fine')
+        mod = types.ModuleType('fine')
         mod.__path__ = ['XXX']
         with importlib_test_util.import_state(meta_path=[BadLoaderFinder]):
             with importlib_test_util.uncache('fine'):
@@ -59,7 +60,7 @@
         # If something in fromlist triggers an exception not related to not
         # existing, let that exception propagate.
         # issue15316
-        mod = imp.new_module('fine')
+        mod = types.ModuleType('fine')
         mod.__path__ = ['XXX']
         with importlib_test_util.import_state(meta_path=[BadLoaderFinder]):
             with importlib_test_util.uncache('fine'):
diff --git a/Lib/test/test_importlib/import_/test_fromlist.py b/Lib/test/test_importlib/import_/test_fromlist.py
--- a/Lib/test/test_importlib/import_/test_fromlist.py
+++ b/Lib/test/test_importlib/import_/test_fromlist.py
@@ -1,7 +1,6 @@
 """Test that the semantics relating to the 'fromlist' argument are correct."""
 from .. import util
 from . import util as import_util
-import imp
 import unittest
 
 class ReturnValue(unittest.TestCase):
diff --git a/Lib/test/test_importlib/source/test_case_sensitivity.py b/Lib/test/test_importlib/source/test_case_sensitivity.py
--- a/Lib/test/test_importlib/source/test_case_sensitivity.py
+++ b/Lib/test/test_importlib/source/test_case_sensitivity.py
@@ -1,9 +1,9 @@
 """Test case-sensitivity (PEP 235)."""
+from .. import util
+from . import util as source_util
+
 from importlib import _bootstrap
 from importlib import machinery
-from .. import util
-from . import util as source_util
-import imp
 import os
 import sys
 from test import support as test_support
diff --git a/Lib/test/test_importlib/source/test_file_loader.py b/Lib/test/test_importlib/source/test_file_loader.py
--- a/Lib/test/test_importlib/source/test_file_loader.py
+++ b/Lib/test/test_importlib/source/test_file_loader.py
@@ -1,6 +1,7 @@
 from importlib import machinery
 import importlib
 import importlib.abc
+import importlib.util
 from .. import abc
 from .. import util
 from . import util as source_util
@@ -13,6 +14,7 @@
 import shutil
 import stat
 import sys
+import types
 import unittest
 
 from test.support import make_legacy_pyc, unload
@@ -112,7 +114,7 @@
         value = '<test>'
         name = '_temp'
         with source_util.create_modules(name) as mapping:
-            orig_module = imp.new_module(name)
+            orig_module = types.ModuleType(name)
             for attr in attributes:
                 setattr(orig_module, attr, value)
             with open(mapping[name], 'w') as file:
@@ -144,11 +146,11 @@
                 loader = machinery.SourceFileLoader('_temp', file_path)
                 mod = loader.load_module('_temp')
                 self.assertEqual(file_path, mod.__file__)
-                self.assertEqual(imp.cache_from_source(file_path),
+                self.assertEqual(importlib.util.cache_from_source(file_path),
                                  mod.__cached__)
         finally:
             os.unlink(file_path)
-            pycache = os.path.dirname(imp.cache_from_source(file_path))
+            pycache = os.path.dirname(importlib.util.cache_from_source(file_path))
             if os.path.exists(pycache):
                 shutil.rmtree(pycache)
 
@@ -157,7 +159,7 @@
         # truncated rather than raise an OverflowError.
         with source_util.create_modules('_temp') as mapping:
             source = mapping['_temp']
-            compiled = imp.cache_from_source(source)
+            compiled = importlib.util.cache_from_source(source)
             with open(source, 'w') as f:
                 f.write("x = 5")
             try:
@@ -194,7 +196,7 @@
             pass
         py_compile.compile(mapping[name])
         if not del_source:
-            bytecode_path = imp.cache_from_source(mapping[name])
+            bytecode_path = importlib.util.cache_from_source(mapping[name])
         else:
             os.unlink(mapping[name])
             bytecode_path = make_legacy_pyc(mapping[name])
@@ -322,7 +324,8 @@
         def test(name, mapping, bytecode_path):
             self.import_(mapping[name], name)
             with open(bytecode_path, 'rb') as bytecode_file:
-                self.assertEqual(bytecode_file.read(4), imp.get_magic())
+                self.assertEqual(bytecode_file.read(4),
+                                 importlib.util.MAGIC_NUMBER)
 
         self._test_bad_magic(test)
 
@@ -372,7 +375,7 @@
         zeros = b'\x00\x00\x00\x00'
         with source_util.create_modules('_temp') as mapping:
             py_compile.compile(mapping['_temp'])
-            bytecode_path = imp.cache_from_source(mapping['_temp'])
+            bytecode_path = importlib.util.cache_from_source(mapping['_temp'])
             with open(bytecode_path, 'r+b') as bytecode_file:
                 bytecode_file.seek(4)
                 bytecode_file.write(zeros)
@@ -390,7 +393,7 @@
         with source_util.create_modules('_temp') as mapping:
             # Create bytecode that will need to be re-created.
             py_compile.compile(mapping['_temp'])
-            bytecode_path = imp.cache_from_source(mapping['_temp'])
+            bytecode_path = importlib.util.cache_from_source(mapping['_temp'])
             with open(bytecode_path, 'r+b') as bytecode_file:
                 bytecode_file.seek(0)
                 bytecode_file.write(b'\x00\x00\x00\x00')
diff --git a/Lib/test/test_importlib/source/test_finder.py b/Lib/test/test_importlib/source/test_finder.py
--- a/Lib/test/test_importlib/source/test_finder.py
+++ b/Lib/test/test_importlib/source/test_finder.py
@@ -3,7 +3,6 @@
 
 from importlib import machinery
 import errno
-import imp
 import os
 import py_compile
 import stat
diff --git a/Lib/test/test_importlib/source/test_path_hook.py b/Lib/test/test_importlib/source/test_path_hook.py
--- a/Lib/test/test_importlib/source/test_path_hook.py
+++ b/Lib/test/test_importlib/source/test_path_hook.py
@@ -1,7 +1,6 @@
 from . import util as source_util
 
 from importlib import machinery
-import imp
 import unittest
 
 
diff --git a/Lib/test/test_importlib/source/util.py b/Lib/test/test_importlib/source/util.py
--- a/Lib/test/test_importlib/source/util.py
+++ b/Lib/test/test_importlib/source/util.py
@@ -2,7 +2,6 @@
 import contextlib
 import errno
 import functools
-import imp
 import os
 import os.path
 import sys
diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py
--- a/Lib/test/test_importlib/test_abc.py
+++ b/Lib/test/test_importlib/test_abc.py
@@ -1,15 +1,16 @@
 import importlib
+import importlib.util
 from importlib import abc
 from importlib import machinery
 
 import contextlib
-import imp
 import inspect
 import io
 import marshal
 import os
 import sys
 from test import support
+import types
 import unittest
 from unittest import mock
 
@@ -140,7 +141,7 @@
             self.ins.load_module('something')
 
     def test_module_repr(self):
-        mod = imp.new_module('blah')
+        mod = types.ModuleType('blah')
         with self.assertRaises(NotImplementedError):
             self.ins.module_repr(mod)
         original_repr = repr(mod)
@@ -205,7 +206,7 @@
 
     def test_init_module_attrs(self):
         loader = LoaderSubclass()
-        module = imp.new_module('blah')
+        module = types.ModuleType('blah')
         loader.init_module_attrs(module)
         self.assertEqual(module.__loader__, loader)
 
@@ -215,7 +216,7 @@
 
     def source_to_module(self, data, path=None):
         """Help with source_to_code() tests."""
-        module = imp.new_module('blah')
+        module = types.ModuleType('blah')
         loader = InspectLoaderSubclass()
         if path is None:
             code = loader.source_to_code(data)
@@ -257,7 +258,7 @@
 
     def test_get_code(self):
         # Test success.
-        module = imp.new_module('blah')
+        module = types.ModuleType('blah')
         with mock.patch.object(InspectLoaderSubclass, 'get_source') as mocked:
             mocked.return_value = 'attr = 42'
             loader = InspectLoaderSubclass()
@@ -289,7 +290,7 @@
 
     def init_module_attrs(self, name):
         loader = InspectLoaderSubclass()
-        module = imp.new_module(name)
+        module = types.ModuleType(name)
         loader.init_module_attrs(module)
         self.assertEqual(module.__loader__, loader)
         return module
@@ -390,7 +391,7 @@
             loader = ExecutionLoaderSubclass()
             code = loader.get_code('blah')
         self.assertEqual(code.co_filename, path)
-        module = imp.new_module('blah')
+        module = types.ModuleType('blah')
         exec(code, module.__dict__)
         self.assertEqual(module.attr, 42)
 
@@ -420,7 +421,7 @@
             loader = ExecutionLoaderSubclass()
             code = loader.get_code('blah')
         self.assertEqual(code.co_filename, '<string>')
-        module = imp.new_module('blah')
+        module = types.ModuleType('blah')
         exec(code, module.__dict__)
         self.assertEqual(module.attr, 42)
 
@@ -444,7 +445,7 @@
         path = os.path.join('some', 'path', '{}.py'.format(name))
         with self.mock_methods(False, path):
             loader = ExecutionLoaderSubclass()
-            module = imp.new_module(name)
+            module = types.ModuleType(name)
             loader.init_module_attrs(module)
         self.assertIs(module.__loader__, loader)
         self.assertEqual(module.__file__, path)
@@ -457,7 +458,7 @@
         path = os.path.join('some', 'pkg', '__init__.py')
         with self.mock_methods(True, path):
             loader = ExecutionLoaderSubclass()
-            module = imp.new_module(name)
+            module = types.ModuleType(name)
             loader.init_module_attrs(module)
         self.assertIs(module.__loader__, loader)
         self.assertEqual(module.__file__, path)
@@ -471,7 +472,7 @@
         path = os.path.join('some', 'pkg', 'submodule.py')
         with self.mock_methods(False, path):
             loader = ExecutionLoaderSubclass()
-            module = imp.new_module(name)
+            module = types.ModuleType(name)
             loader.init_module_attrs(module)
         self.assertEqual(module.__package__, 'pkg')
         self.assertEqual(module.__file__, path)
@@ -484,7 +485,7 @@
         with self.mock_methods(False, path) as mocked_methods:
             mocked_methods['get_filename'].side_effect = ImportError
             loader = ExecutionLoaderSubclass()
-            module = imp.new_module(name)
+            module = types.ModuleType(name)
             loader.init_module_attrs(module)
         self.assertFalse(hasattr(module, '__file__'))
 
@@ -515,9 +516,9 @@
 
     source_mtime = 1
 
-    def __init__(self, path, magic=imp.get_magic()):
+    def __init__(self, path, magic=importlib.util.MAGIC_NUMBER):
         super().__init__(path)
-        self.bytecode_path = imp.cache_from_source(self.path)
+        self.bytecode_path = importlib.util.cache_from_source(self.path)
         self.source_size = len(self.source)
         data = bytearray(magic)
         data.extend(importlib._w_long(self.source_mtime))
@@ -557,7 +558,7 @@
             module_name = 'mod'
             self.path = os.path.join(self.package, '.'.join(['mod', 'py']))
             self.name = '.'.join([self.package, module_name])
-        self.cached = imp.cache_from_source(self.path)
+        self.cached = importlib.util.cache_from_source(self.path)
         self.loader = self.loader_mock(self.path, **kwargs)
 
     def verify_module(self, module):
@@ -574,7 +575,7 @@
         self.assertEqual(values[4], repr(self.loader))
 
     def verify_code(self, code_object):
-        module = imp.new_module(self.name)
+        module = types.ModuleType(self.name)
         module.__file__ = self.path
         module.__cached__ = self.cached
         module.__package__ = self.package
@@ -673,7 +674,7 @@
         super().verify_code(code_object)
         if bytecode_written:
             self.assertIn(self.cached, self.loader.written)
-            data = bytearray(imp.get_magic())
+            data = bytearray(importlib.util.MAGIC_NUMBER)
             data.extend(importlib._w_long(self.loader.source_mtime))
             data.extend(importlib._w_long(self.loader.source_size))
             data.extend(marshal.dumps(code_object))
@@ -689,7 +690,7 @@
         self.loader.bytecode_path = "<does not exist>"
         # Sanity check
         with self.assertRaises(OSError):
-            bytecode_path = imp.cache_from_source(self.path)
+            bytecode_path = importlib.util.cache_from_source(self.path)
             self.loader.get_data(bytecode_path)
         code_object = self.loader.get_code(self.name)
         self.verify_code(code_object, bytecode_written=True)
@@ -787,26 +788,26 @@
     """Tests for importlib.abc.SourceLoader.init_module_attrs()."""
 
     def test_init_module_attrs(self):
-        # If __file__ set, __cached__ == imp.cached_from_source(__file__).
+        # If __file__ set, __cached__ == importlib.util.cached_from_source(__file__).
         name = 'blah'
         path = 'blah.py'
         loader = SourceOnlyLoaderMock(path)
-        module = imp.new_module(name)
+        module = types.ModuleType(name)
         loader.init_module_attrs(module)
         self.assertEqual(module.__loader__, loader)
         self.assertEqual(module.__package__, '')
         self.assertEqual(module.__file__, path)
-        self.assertEqual(module.__cached__, imp.cache_from_source(path))
+        self.assertEqual(module.__cached__, importlib.util.cache_from_source(path))
 
     @mock.patch('importlib._bootstrap.cache_from_source')
     def test_cache_from_source_NotImplementedError(self, mock_cache_from_source):
-        # If imp.cache_from_source() raises NotImplementedError don't set
+        # If importlib.util.cache_from_source() raises NotImplementedError don't set
         # __cached__.
         mock_cache_from_source.side_effect = NotImplementedError
         name = 'blah'
         path = 'blah.py'
         loader = SourceOnlyLoaderMock(path)
-        module = imp.new_module(name)
+        module = types.ModuleType(name)
         loader.init_module_attrs(module)
         self.assertEqual(module.__file__, path)
         self.assertFalse(hasattr(module, '__cached__'))
@@ -817,7 +818,7 @@
             mocked.side_effect = ImportError
             name = 'blah'
             loader = SourceOnlyLoaderMock('blah.py')
-            module = imp.new_module(name)
+            module = types.ModuleType(name)
             loader.init_module_attrs(module)
         self.assertFalse(hasattr(module, '__file__'))
         self.assertFalse(hasattr(module, '__cached__'))
diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py
--- a/Lib/test/test_importlib/test_api.py
+++ b/Lib/test/test_importlib/test_api.py
@@ -1,5 +1,5 @@
 from . import util
-import imp
+
 import importlib
 from importlib import _bootstrap
 from importlib import machinery
@@ -99,7 +99,7 @@
         # If a module with __loader__ is in sys.modules, then return it.
         name = 'some_mod'
         with util.uncache(name):
-            module = imp.new_module(name)
+            module = types.ModuleType(name)
             loader = 'a loader!'
             module.__loader__ = loader
             sys.modules[name] = module
@@ -110,7 +110,7 @@
         # If sys.modules[name].__loader__ is None, raise ValueError.
         name = 'some_mod'
         with util.uncache(name):
-            module = imp.new_module(name)
+            module = types.ModuleType(name)
             module.__loader__ = None
             sys.modules[name] = module
             with self.assertRaises(ValueError):
@@ -121,7 +121,7 @@
         # Issue #17099
         name = 'some_mod'
         with util.uncache(name):
-            module = imp.new_module(name)
+            module = types.ModuleType(name)
             try:
                 del module.__loader__
             except AttributeError:
@@ -189,7 +189,7 @@
     def test_method_lacking(self):
         # There should be no issues if the method is not defined.
         key = 'gobbledeegook'
-        sys.path_importer_cache[key] = imp.NullImporter('abc')
+        sys.path_importer_cache[key] = None
         self.addCleanup(lambda: sys.path_importer_cache.__delitem__(key))
         importlib.invalidate_caches()  # Shouldn't trigger an exception.
 
diff --git a/Lib/test/test_importlib/test_util.py b/Lib/test/test_importlib/test_util.py
--- a/Lib/test/test_importlib/test_util.py
+++ b/Lib/test/test_importlib/test_util.py
@@ -1,6 +1,6 @@
 from importlib import util
 from . import util as test_util
-import imp
+
 import os
 import sys
 from test import support
@@ -40,14 +40,14 @@
 
     def test_reload(self):
         # Test that the same module is in sys.modules.
-        created_module = imp.new_module(self.module_name)
+        created_module = types.ModuleType(self.module_name)
         sys.modules[self.module_name] = created_module
         with util.module_to_load(self.module_name) as module:
             self.assertIs(module, created_module)
 
     def test_reload_failed(self):
         # Test that the module was left in sys.modules.
-        created_module = imp.new_module(self.module_name)
+        created_module = types.ModuleType(self.module_name)
         sys.modules[self.module_name] = created_module
         try:
             with util.module_to_load(self.module_name) as module:
@@ -60,7 +60,7 @@
     def test_reset_name(self):
         # If reset_name is true then module.__name__ = name, else leave it be.
         odd_name = 'not your typical name'
-        created_module = imp.new_module(self.module_name)
+        created_module = types.ModuleType(self.module_name)
         created_module.__name__ = odd_name
         sys.modules[self.module_name] = created_module
         with util.module_to_load(self.module_name) as module:
@@ -119,7 +119,7 @@
             def load_module(self, module):
                 return module
         name = 'a.b.c'
-        module = imp.new_module('a.b.c')
+        module = types.ModuleType('a.b.c')
         module.__loader__ = 42
         module.__package__ = 42
         with test_util.uncache(name):
@@ -141,7 +141,7 @@
     def test_reload_failure(self):
         # Test that a failure on reload leaves the module in-place.
         name = 'a.b.c'
-        module = imp.new_module(name)
+        module = types.ModuleType(name)
         with test_util.uncache(name):
             sys.modules[name] = module
             self.raise_exception(name)
@@ -212,26 +212,26 @@
     def test_top_level(self):
         # __package__ should be set to the empty string if a top-level module.
         # Implicitly tests when package is set to None.
-        module = imp.new_module('module')
+        module = types.ModuleType('module')
         module.__package__ = None
         self.verify(module, '')
 
     def test_package(self):
         # Test setting __package__ for a package.
-        module = imp.new_module('pkg')
+        module = types.ModuleType('pkg')
         module.__path__ = ['<path>']
         module.__package__ = None
         self.verify(module, 'pkg')
 
     def test_submodule(self):
         # Test __package__ for a module in a package.
-        module = imp.new_module('pkg.mod')
+        module = types.ModuleType('pkg.mod')
         module.__package__ = None
         self.verify(module, 'pkg')
 
     def test_setting_if_missing(self):
         # __package__ should be set if it is missing.
-        module = imp.new_module('mod')
+        module = types.ModuleType('mod')
         if hasattr(module, '__package__'):
             delattr(module, '__package__')
         self.verify(module, '')
@@ -239,7 +239,7 @@
     def test_leaving_alone(self):
         # If __package__ is set and not None then leave it alone.
         for value in (True, False):
-            module = imp.new_module('mod')
+            module = types.ModuleType('mod')
             module.__package__ = value
             self.verify(module, value)
 
@@ -261,7 +261,7 @@
 
     def test_no_attribute(self):
         loader = self.DummyLoader()
-        loader.module = imp.new_module('blah')
+        loader.module = types.ModuleType('blah')
         try:
             del loader.module.__loader__
         except AttributeError:
@@ -270,13 +270,13 @@
 
     def test_attribute_is_None(self):
         loader = self.DummyLoader()
-        loader.module = imp.new_module('blah')
+        loader.module = types.ModuleType('blah')
         loader.module.__loader__ = None
         self.assertEqual(loader, loader.load_module('blah').__loader__)
 
     def test_not_reset(self):
         loader = self.DummyLoader()
-        loader.module = imp.new_module('blah')
+        loader.module = types.ModuleType('blah')
         loader.module.__loader__ = 42
         self.assertEqual(42, loader.load_module('blah').__loader__)
 
@@ -331,7 +331,7 @@
 
     """
 
-    tag = imp.get_tag()
+    tag = sys.implementation.cache_tag
 
     @unittest.skipUnless(sys.implementation.cache_tag is not None,
                          'requires sys.implementation.cache_tag not be None')
diff --git a/Lib/test/test_importlib/util.py b/Lib/test/test_importlib/util.py
--- a/Lib/test/test_importlib/util.py
+++ b/Lib/test/test_importlib/util.py
@@ -1,9 +1,9 @@
 from contextlib import contextmanager
-import imp
 import os.path
 from test import support
 import unittest
 import sys
+import types
 
 
 CASE_INSENSITIVE_FS = True
@@ -98,7 +98,7 @@
                 package = name.rsplit('.', 1)[0]
             else:
                 package = import_name
-            module = imp.new_module(import_name)
+            module = types.ModuleType(import_name)
             module.__loader__ = self
             module.__file__ = '<mock __file__>'
             module.__package__ = package

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list