mirror of https://github.com/python/cpython.git
Issue #17177: Stop using imp in a bunch of tests
This commit is contained in:
parent
8a2a902f88
commit
9529fbfd36
|
@ -12,7 +12,7 @@
|
||||||
import shutil
|
import shutil
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
from imp import source_from_cache
|
from importlib.util import source_from_cache
|
||||||
from test.support import make_legacy_pyc, strip_python_stderr
|
from test.support import make_legacy_pyc, strip_python_stderr
|
||||||
|
|
||||||
# Executing the interpreter in a subprocess
|
# Executing the interpreter in a subprocess
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
import warnings
|
import warnings
|
||||||
import unittest
|
import unittest
|
||||||
import importlib
|
import importlib
|
||||||
|
import importlib.util
|
||||||
import collections.abc
|
import collections.abc
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import imp
|
|
||||||
import time
|
import time
|
||||||
import sysconfig
|
import sysconfig
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
@ -316,7 +316,7 @@ def make_legacy_pyc(source):
|
||||||
does not need to exist, however the PEP 3147 pyc file must exist.
|
does not need to exist, however the PEP 3147 pyc file must exist.
|
||||||
:return: The file system path to the legacy pyc file.
|
:return: The file system path to the legacy pyc file.
|
||||||
"""
|
"""
|
||||||
pyc_file = imp.cache_from_source(source)
|
pyc_file = importlib.util.cache_from_source(source)
|
||||||
up_one = os.path.dirname(os.path.abspath(source))
|
up_one = os.path.dirname(os.path.abspath(source))
|
||||||
legacy_pyc = os.path.join(up_one, source + ('c' if __debug__ else 'o'))
|
legacy_pyc = os.path.join(up_one, source + ('c' if __debug__ else 'o'))
|
||||||
os.rename(pyc_file, legacy_pyc)
|
os.rename(pyc_file, legacy_pyc)
|
||||||
|
@ -335,8 +335,8 @@ def forget(modname):
|
||||||
# combinations of PEP 3147 and legacy pyc and pyo files.
|
# combinations of PEP 3147 and legacy pyc and pyo files.
|
||||||
unlink(source + 'c')
|
unlink(source + 'c')
|
||||||
unlink(source + 'o')
|
unlink(source + 'o')
|
||||||
unlink(imp.cache_from_source(source, debug_override=True))
|
unlink(importlib.util.cache_from_source(source, debug_override=True))
|
||||||
unlink(imp.cache_from_source(source, debug_override=False))
|
unlink(importlib.util.cache_from_source(source, debug_override=False))
|
||||||
|
|
||||||
# On some platforms, should not run gui test even if it is allowed
|
# On some platforms, should not run gui test even if it is allowed
|
||||||
# in `use_resources'.
|
# in `use_resources'.
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
# A test suite for pdb; not very comprehensive at the moment.
|
# A test suite for pdb; not very comprehensive at the moment.
|
||||||
|
|
||||||
import doctest
|
import doctest
|
||||||
import imp
|
|
||||||
import pdb
|
import pdb
|
||||||
import sys
|
import sys
|
||||||
|
import types
|
||||||
import unittest
|
import unittest
|
||||||
import subprocess
|
import subprocess
|
||||||
import textwrap
|
import textwrap
|
||||||
|
@ -464,7 +464,7 @@ def test_pdb_skip_modules():
|
||||||
|
|
||||||
|
|
||||||
# Module for testing skipping of module that makes a callback
|
# Module for testing skipping of module that makes a callback
|
||||||
mod = imp.new_module('module_to_skip')
|
mod = types.ModuleType('module_to_skip')
|
||||||
exec('def foo_pony(callback): x = 1; callback(); return None', mod.__dict__)
|
exec('def foo_pony(callback): x = 1; callback(); return None', mod.__dict__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from imp import cache_from_source
|
from importlib.util import cache_from_source
|
||||||
from test.support import run_unittest, create_empty_file
|
from test.support import run_unittest, create_empty_file
|
||||||
|
|
||||||
class TestImport(unittest.TestCase):
|
class TestImport(unittest.TestCase):
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
from test.support import run_unittest, unload, check_warnings
|
from test.support import run_unittest, unload, check_warnings
|
||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
import imp
|
|
||||||
import importlib
|
import importlib
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import types
|
||||||
import shutil
|
import shutil
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class PkgutilPEP302Tests(unittest.TestCase):
|
||||||
class MyTestLoader(object):
|
class MyTestLoader(object):
|
||||||
def load_module(self, fullname):
|
def load_module(self, fullname):
|
||||||
# Create an empty module
|
# Create an empty module
|
||||||
mod = sys.modules.setdefault(fullname, imp.new_module(fullname))
|
mod = sys.modules.setdefault(fullname, types.ModuleType(fullname))
|
||||||
mod.__file__ = "<%s>" % self.__class__.__name__
|
mod.__file__ = "<%s>" % self.__class__.__name__
|
||||||
mod.__loader__ = self
|
mod.__loader__ = self
|
||||||
# Make it a package
|
# Make it a package
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
Nick Mathewson
|
Nick Mathewson
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import imp
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import importlib
|
import importlib
|
||||||
|
import importlib.util
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from test.support import run_unittest, create_empty_file, verbose
|
from test.support import run_unittest, create_empty_file, verbose
|
||||||
|
@ -241,7 +241,8 @@ def _check_path_limitations(self, module_name):
|
||||||
source_path_len += 2 * (len(self.longname) + 1)
|
source_path_len += 2 * (len(self.longname) + 1)
|
||||||
# a path separator + `module_name` + ".py"
|
# a path separator + `module_name` + ".py"
|
||||||
source_path_len += len(module_name) + 1 + len(".py")
|
source_path_len += len(module_name) + 1 + len(".py")
|
||||||
cached_path_len = source_path_len + len(imp.cache_from_source("x.py")) - len("x.py")
|
cached_path_len = (source_path_len +
|
||||||
|
len(importlib.util.cache_from_source("x.py")) - len("x.py"))
|
||||||
if os.name == 'nt' and cached_path_len >= 258:
|
if os.name == 'nt' and cached_path_len >= 258:
|
||||||
# Under Windows, the max path len is 260 including C's terminating
|
# Under Windows, the max path len is 260 including C's terminating
|
||||||
# NUL character.
|
# NUL character.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import marshal
|
import marshal
|
||||||
import imp
|
import importlib.util
|
||||||
import struct
|
import struct
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -34,7 +34,8 @@ def make_pyc(co, mtime, size):
|
||||||
mtime = int(mtime)
|
mtime = int(mtime)
|
||||||
else:
|
else:
|
||||||
mtime = int(-0x100000000 + int(mtime))
|
mtime = int(-0x100000000 + int(mtime))
|
||||||
pyc = imp.get_magic() + struct.pack("<ii", int(mtime), size & 0xFFFFFFFF) + data
|
pyc = (importlib.util.MAGIC_NUMBER +
|
||||||
|
struct.pack("<ii", int(mtime), size & 0xFFFFFFFF) + data)
|
||||||
return pyc
|
return pyc
|
||||||
|
|
||||||
def module_path_to_dotted_name(path):
|
def module_path_to_dotted_name(path):
|
||||||
|
@ -49,7 +50,7 @@ def module_path_to_dotted_name(path):
|
||||||
TESTPACK2 = "ziptestpackage2"
|
TESTPACK2 = "ziptestpackage2"
|
||||||
TEMP_ZIP = os.path.abspath("junk95142.zip")
|
TEMP_ZIP = os.path.abspath("junk95142.zip")
|
||||||
|
|
||||||
pyc_file = imp.cache_from_source(TESTMOD + '.py')
|
pyc_file = importlib.util.cache_from_source(TESTMOD + '.py')
|
||||||
pyc_ext = ('.pyc' if __debug__ else '.pyo')
|
pyc_ext = ('.pyc' if __debug__ else '.pyo')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue