diff options
author | Brett Cannon <brett@python.org> | 2013-06-16 17:13:40 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-06-16 17:13:40 (GMT) |
commit | e4f41deccf94ccc798b1eb1f44657ade66669a60 (patch) | |
tree | 8f47ca73224c628f4afcebb9dd989cac73d0f8d1 /Lib/test | |
parent | 39295e7a55d03b9ef31c0d0dd27d129b1ad5a695 (diff) | |
download | cpython-e4f41deccf94ccc798b1eb1f44657ade66669a60.zip cpython-e4f41deccf94ccc798b1eb1f44657ade66669a60.tar.gz cpython-e4f41deccf94ccc798b1eb1f44657ade66669a60.tar.bz2 |
Issue #17177: The imp module is pending deprecation.
To make sure there is no issue with code that is both Python 2 and 3
compatible, there are no plans to remove the module any sooner than
Python 4 (unless the community moves to Python 3 solidly before then).
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_fork1.py | 2 | ||||
-rw-r--r-- | Lib/test/test_imp.py | 4 | ||||
-rw-r--r-- | Lib/test/test_import.py | 32 | ||||
-rw-r--r-- | Lib/test/test_importlib/import_/test_api.py | 1 | ||||
-rw-r--r-- | Lib/test/test_importlib/source/test_file_loader.py | 1 | ||||
-rw-r--r-- | Lib/test/test_socketserver.py | 2 | ||||
-rw-r--r-- | Lib/test/test_threaded_import.py | 2 |
7 files changed, 22 insertions, 22 deletions
diff --git a/Lib/test/test_fork1.py b/Lib/test/test_fork1.py index 8192c38..e0626df 100644 --- a/Lib/test/test_fork1.py +++ b/Lib/test/test_fork1.py @@ -1,7 +1,7 @@ """This test checks for correct fork() behavior. """ -import imp +import _imp as imp import os import signal import sys diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index dc62423..cf50ea4 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -2,7 +2,6 @@ try: import _thread except ImportError: _thread = None -import imp import importlib import os import os.path @@ -11,6 +10,9 @@ import sys from test import support import unittest import warnings +with warnings.catch_warnings(): + warnings.simplefilter('ignore', PendingDeprecationWarning) + import imp def requires_load_dynamic(meth): diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 673fb41..26b5806 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -1,7 +1,7 @@ # We import importlib *ASAP* in order to test #15386 import importlib +import importlib.util import builtins -import imp from test.test_importlib.import_ import util as importlib_util import marshal import os @@ -221,7 +221,7 @@ class ImportTests(unittest.TestCase): with open(source, "w") as f: f.write("a = 10\nb=20//0\n") - self.assertRaises(ZeroDivisionError, imp.reload, mod) + self.assertRaises(ZeroDivisionError, importlib.reload, mod) # But we still expect the module to be in sys.modules. mod = sys.modules.get(TESTFN) self.assertIsNot(mod, None, "expected module to be in sys.modules") @@ -287,7 +287,7 @@ class ImportTests(unittest.TestCase): import sys class C: def __del__(self): - import imp + import importlib sys.argv.insert(0, C()) """)) script_helper.assert_python_ok(testfn) @@ -298,7 +298,7 @@ class ImportTests(unittest.TestCase): sys.path.insert(0, os.curdir) try: source = TESTFN + ".py" - compiled = imp.cache_from_source(source) + compiled = importlib.util.cache_from_source(source) with open(source, 'w') as f: pass try: @@ -339,7 +339,7 @@ class FilePermissionTests(unittest.TestCase): def test_creation_mode(self): mask = 0o022 with temp_umask(mask), _ready_to_import() as (name, path): - cached_path = imp.cache_from_source(path) + cached_path = importlib.util.cache_from_source(path) module = __import__(name) if not os.path.exists(cached_path): self.fail("__import__ did not result in creation of " @@ -357,7 +357,7 @@ class FilePermissionTests(unittest.TestCase): # permissions of .pyc should match those of .py, regardless of mask mode = 0o600 with temp_umask(0o022), _ready_to_import() as (name, path): - cached_path = imp.cache_from_source(path) + cached_path = importlib.util.cache_from_source(path) os.chmod(path, mode) __import__(name) if not os.path.exists(cached_path): @@ -372,7 +372,7 @@ class FilePermissionTests(unittest.TestCase): def test_cached_readonly(self): mode = 0o400 with temp_umask(0o022), _ready_to_import() as (name, path): - cached_path = imp.cache_from_source(path) + cached_path = importlib.util.cache_from_source(path) os.chmod(path, mode) __import__(name) if not os.path.exists(cached_path): @@ -412,7 +412,7 @@ class FilePermissionTests(unittest.TestCase): bytecode_only = path + "c" else: bytecode_only = path + "o" - os.rename(imp.cache_from_source(path), bytecode_only) + os.rename(importlib.util.cache_from_source(path), bytecode_only) m = __import__(name) self.assertEqual(m.x, 'rewritten') @@ -434,7 +434,7 @@ func_filename = func.__code__.co_filename """ dir_name = os.path.abspath(TESTFN) file_name = os.path.join(dir_name, module_name) + os.extsep + "py" - compiled_name = imp.cache_from_source(file_name) + compiled_name = importlib.util.cache_from_source(file_name) def setUp(self): self.sys_path = sys.path[:] @@ -637,7 +637,7 @@ class OverridingImportBuiltinTests(unittest.TestCase): class PycacheTests(unittest.TestCase): # Test the various PEP 3147 related behaviors. - tag = imp.get_tag() + tag = sys.implementation.cache_tag def _clean(self): forget(TESTFN) @@ -685,7 +685,7 @@ class PycacheTests(unittest.TestCase): # With PEP 3147 cache layout, removing the source but leaving the pyc # file does not satisfy the import. __import__(TESTFN) - pyc_file = imp.cache_from_source(self.source) + pyc_file = importlib.util.cache_from_source(self.source) self.assertTrue(os.path.exists(pyc_file)) os.remove(self.source) forget(TESTFN) @@ -710,7 +710,7 @@ class PycacheTests(unittest.TestCase): def test___cached__(self): # Modules now also have an __cached__ that points to the pyc file. m = __import__(TESTFN) - pyc_file = imp.cache_from_source(TESTFN + '.py') + pyc_file = importlib.util.cache_from_source(TESTFN + '.py') self.assertEqual(m.__cached__, os.path.join(os.curdir, pyc_file)) @skip_if_dont_write_bytecode @@ -745,10 +745,10 @@ class PycacheTests(unittest.TestCase): pass importlib.invalidate_caches() m = __import__('pep3147.foo') - init_pyc = imp.cache_from_source( + init_pyc = importlib.util.cache_from_source( os.path.join('pep3147', '__init__.py')) self.assertEqual(m.__cached__, os.path.join(os.curdir, init_pyc)) - foo_pyc = imp.cache_from_source(os.path.join('pep3147', 'foo.py')) + foo_pyc = importlib.util.cache_from_source(os.path.join('pep3147', 'foo.py')) self.assertEqual(sys.modules['pep3147.foo'].__cached__, os.path.join(os.curdir, foo_pyc)) @@ -772,10 +772,10 @@ class PycacheTests(unittest.TestCase): unload('pep3147') importlib.invalidate_caches() m = __import__('pep3147.foo') - init_pyc = imp.cache_from_source( + init_pyc = importlib.util.cache_from_source( os.path.join('pep3147', '__init__.py')) self.assertEqual(m.__cached__, os.path.join(os.curdir, init_pyc)) - foo_pyc = imp.cache_from_source(os.path.join('pep3147', 'foo.py')) + foo_pyc = importlib.util.cache_from_source(os.path.join('pep3147', 'foo.py')) self.assertEqual(sys.modules['pep3147.foo'].__cached__, os.path.join(os.curdir, foo_pyc)) diff --git a/Lib/test/test_importlib/import_/test_api.py b/Lib/test/test_importlib/import_/test_api.py index 98f79d6..b83cead 100644 --- a/Lib/test/test_importlib/import_/test_api.py +++ b/Lib/test/test_importlib/import_/test_api.py @@ -1,6 +1,5 @@ from .. import util as importlib_test_util from . import util -import imp import sys import types import unittest diff --git a/Lib/test/test_importlib/source/test_file_loader.py b/Lib/test/test_importlib/source/test_file_loader.py index 616e775..66ad96e 100644 --- a/Lib/test/test_importlib/source/test_file_loader.py +++ b/Lib/test/test_importlib/source/test_file_loader.py @@ -7,7 +7,6 @@ from .. import util from . import util as source_util import errno -import imp import marshal import os import py_compile diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index 84a5e7b..02c6c1e 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -2,8 +2,8 @@ Test suite for socketserver. """ +import _imp as imp import contextlib -import imp import os import select import signal diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py index 6c2965b..3d961b5 100644 --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -5,8 +5,8 @@ # complains several times about module random having no attribute # randrange, and then Python hangs. +import _imp as imp import os -import imp import importlib import sys import time |