from test.test_importlib import util as test_util machinery = test_util.import_importlib('importlib.machinery') import os import re import sys import unittest import warnings from test.support import import_helper from contextlib import contextmanager from test.test_importlib.util import temp_module import_helper.import_module('winreg', required_on=['win']) from winreg import ( CreateKey, HKEY_CURRENT_USER, SetValue, REG_SZ, KEY_ALL_ACCESS, EnumKey, CloseKey, DeleteKey, OpenKey ) def get_platform(): # Port of distutils.util.get_platform(). TARGET_TO_PLAT = { 'x86' : 'win32', 'x64' : 'win-amd64', 'arm' : 'win-arm32', } if ('VSCMD_ARG_TGT_ARCH' in os.environ and os.environ['VSCMD_ARG_TGT_ARCH'] in TARGET_TO_PLAT): return TARGET_TO_PLAT[os.environ['VSCMD_ARG_TGT_ARCH']] elif 'amd64' in sys.version.lower(): return 'win-amd64'
from test.test_importlib import util as test_util init = test_util.import_importlib('importlib') import sys import threading import unittest import weakref from test import support from test.support import threading_helper from test import lock_tests threading_helper.requires_working_threading(module=True) class ModuleLockAsRLockTests: locktype = classmethod(lambda cls: cls.LockType("some_lock")) # _is_owned() unsupported test__is_owned = None # acquire(blocking=False) unsupported test_try_acquire = None test_try_acquire_contended = None # `with` unsupported test_with = None # acquire(timeout=...) unsupported test_timeout = None # _release_save() unsupported test_release_save_unacquired = None # lock status in repr unsupported
from test.test_importlib import abc, util importlib = util.import_importlib('importlib') importlib_abc = util.import_importlib('importlib.abc') machinery = util.import_importlib('importlib.machinery') importlib_util = util.import_importlib('importlib.util') import errno import marshal import os import py_compile import shutil import stat import sys import types import unittest import warnings from test.support.import_helper import make_legacy_pyc, unload from test.test_py_compile import without_source_date_epoch from test.test_py_compile import SourceDateEpochTestMeta class SimpleTest(abc.LoaderTests): """Should have no issue importing a source module [basic]. And if there is a syntax error, it should raise a SyntaxError [syntax error]. """ def setUp(self): self.name = 'spam'
from test.test_importlib import abc, util machinery = util.import_importlib('importlib.machinery') import unittest import sys class FinderTests(abc.FinderTests): """Test the finder for extension modules.""" def setUp(self): if not self.machinery.EXTENSION_SUFFIXES: raise unittest.SkipTest("Requires dynamic loading support.") if util.EXTENSIONS.name in sys.builtin_module_names: raise unittest.SkipTest( f"{util.EXTENSIONS.name} is a builtin module") def find_spec(self, fullname): importer = self.machinery.FileFinder( util.EXTENSIONS.path, (self.machinery.ExtensionFileLoader, self.machinery.EXTENSION_SUFFIXES)) return importer.find_spec(fullname) def test_module(self): self.assertTrue(self.find_spec(util.EXTENSIONS.name)) # No extension module as an __init__ available for testing. test_package = test_package_in_package = None # No extension module in a package available for testing.
import io import marshal import os import sys from test import support from test.support import import_helper import types import unittest from unittest import mock import warnings from test.test_importlib import util as test_util init = test_util.import_importlib('importlib') abc = test_util.import_importlib('importlib.abc') machinery = test_util.import_importlib('importlib.machinery') util = test_util.import_importlib('importlib.util') ##### Inheritance ############################################################## class InheritanceTests: """Test that the specified class is a subclass/superclass of the expected classes.""" subclasses = [] superclasses = [] def setUp(self): self.superclasses = [ getattr(self.abc, class_name) for class_name in self.superclass_names
def test_raises_ModuleNotFoundError(self): with self.assertRaises(ModuleNotFoundError): util.import_importlib('some module that does not exist')