Commit 3497c0bf authored by Eric Snow's avatar Eric Snow

Issue #21503: Use test_both() consistently in test_importlib.

parent d50cee20
from .. import abc from .. import abc
from .. import util from .. import util
frozen_machinery, source_machinery = util.import_importlib('importlib.machinery') machinery = util.import_importlib('importlib.machinery')
import sys import sys
import unittest import unittest
...@@ -44,8 +44,10 @@ class FindSpecTests(abc.FinderTests): ...@@ -44,8 +44,10 @@ class FindSpecTests(abc.FinderTests):
['pkg']) ['pkg'])
self.assertIsNone(spec) self.assertIsNone(spec)
Frozen_FindSpecTests, Source_FindSpecTests = util.test_both(FindSpecTests,
machinery=[frozen_machinery, source_machinery]) (Frozen_FindSpecTests,
Source_FindSpecTests
) = util.test_both(FindSpecTests, machinery=machinery)
@unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module') @unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module')
...@@ -78,8 +80,10 @@ class FinderTests(abc.FinderTests): ...@@ -78,8 +80,10 @@ class FinderTests(abc.FinderTests):
['pkg']) ['pkg'])
self.assertIsNone(loader) self.assertIsNone(loader)
Frozen_FinderTests, Source_FinderTests = util.test_both(FinderTests,
machinery=[frozen_machinery, source_machinery]) (Frozen_FinderTests,
Source_FinderTests
) = util.test_both(FinderTests, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
from .. import abc from .. import abc
from .. import util from .. import util
frozen_machinery, source_machinery = util.import_importlib('importlib.machinery') machinery = util.import_importlib('importlib.machinery')
import sys import sys
import types import types
...@@ -65,8 +65,9 @@ class LoaderTests(abc.LoaderTests): ...@@ -65,8 +65,9 @@ class LoaderTests(abc.LoaderTests):
self.assertEqual(cm.exception.name, module_name) self.assertEqual(cm.exception.name, module_name)
Frozen_LoaderTests, Source_LoaderTests = util.test_both(LoaderTests, (Frozen_LoaderTests,
machinery=[frozen_machinery, source_machinery]) Source_LoaderTests
) = util.test_both(LoaderTests, machinery=machinery)
@unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module') @unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module')
...@@ -98,9 +99,10 @@ class InspectLoaderTests: ...@@ -98,9 +99,10 @@ class InspectLoaderTests:
method(util.BUILTINS.bad_name) method(util.BUILTINS.bad_name)
self.assertRaises(util.BUILTINS.bad_name) self.assertRaises(util.BUILTINS.bad_name)
Frozen_InspectLoaderTests, Source_InspectLoaderTests = util.test_both(
InspectLoaderTests, (Frozen_InspectLoaderTests,
machinery=[frozen_machinery, source_machinery]) Source_InspectLoaderTests
) = util.test_both(InspectLoaderTests, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -5,7 +5,7 @@ import unittest ...@@ -5,7 +5,7 @@ import unittest
from .. import util from .. import util
frozen_machinery, source_machinery = util.import_importlib('importlib.machinery') machinery = util.import_importlib('importlib.machinery')
# XXX find_spec tests # XXX find_spec tests
...@@ -41,9 +41,10 @@ class ExtensionModuleCaseSensitivityTest: ...@@ -41,9 +41,10 @@ class ExtensionModuleCaseSensitivityTest:
loader = self.find_module() loader = self.find_module()
self.assertTrue(hasattr(loader, 'load_module')) self.assertTrue(hasattr(loader, 'load_module'))
Frozen_ExtensionCaseSensitivity, Source_ExtensionCaseSensitivity = util.test_both(
ExtensionModuleCaseSensitivityTest, (Frozen_ExtensionCaseSensitivity,
machinery=[frozen_machinery, source_machinery]) Source_ExtensionCaseSensitivity
) = util.test_both(ExtensionModuleCaseSensitivityTest, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -35,8 +35,10 @@ class FinderTests(abc.FinderTests): ...@@ -35,8 +35,10 @@ class FinderTests(abc.FinderTests):
def test_failure(self): def test_failure(self):
self.assertIsNone(self.find_module('asdfjkl;')) self.assertIsNone(self.find_module('asdfjkl;'))
Frozen_FinderTests, Source_FinderTests = util.test_both(
FinderTests, machinery=machinery) (Frozen_FinderTests,
Source_FinderTests
) = util.test_both(FinderTests, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -76,8 +76,9 @@ class LoaderTests(abc.LoaderTests): ...@@ -76,8 +76,9 @@ class LoaderTests(abc.LoaderTests):
loader = self.machinery.ExtensionFileLoader('pkg', path) loader = self.machinery.ExtensionFileLoader('pkg', path)
self.assertTrue(loader.is_package('pkg')) self.assertTrue(loader.is_package('pkg'))
Frozen_LoaderTests, Source_LoaderTests = util.test_both( (Frozen_LoaderTests,
LoaderTests, machinery=machinery) Source_LoaderTests
) = util.test_both(LoaderTests, machinery=machinery)
......
...@@ -23,8 +23,10 @@ class PathHookTests: ...@@ -23,8 +23,10 @@ class PathHookTests:
# exists. # exists.
self.assertTrue(hasattr(self.hook(util.EXTENSIONS.path), 'find_module')) self.assertTrue(hasattr(self.hook(util.EXTENSIONS.path), 'find_module'))
Frozen_PathHooksTests, Source_PathHooksTests = util.test_both(
PathHookTests, machinery=machinery) (Frozen_PathHooksTests,
Source_PathHooksTests
) = util.test_both(PathHookTests, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -37,8 +37,10 @@ class FindSpecTests(abc.FinderTests): ...@@ -37,8 +37,10 @@ class FindSpecTests(abc.FinderTests):
spec = self.find('<not real>') spec = self.find('<not real>')
self.assertIsNone(spec) self.assertIsNone(spec)
Frozen_FindSpecTests, Source_FindSpecTests = util.test_both(FindSpecTests,
machinery=machinery) (Frozen_FindSpecTests,
Source_FindSpecTests
) = util.test_both(FindSpecTests, machinery=machinery)
class FinderTests(abc.FinderTests): class FinderTests(abc.FinderTests):
...@@ -72,8 +74,10 @@ class FinderTests(abc.FinderTests): ...@@ -72,8 +74,10 @@ class FinderTests(abc.FinderTests):
loader = self.find('<not real>') loader = self.find('<not real>')
self.assertIsNone(loader) self.assertIsNone(loader)
Frozen_FinderTests, Source_FinderTests = util.test_both(FinderTests,
machinery=machinery) (Frozen_FinderTests,
Source_FinderTests
) = util.test_both(FinderTests, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -85,8 +85,10 @@ class ExecModuleTests(abc.LoaderTests): ...@@ -85,8 +85,10 @@ class ExecModuleTests(abc.LoaderTests):
self.exec_module('_not_real') self.exec_module('_not_real')
self.assertEqual(cm.exception.name, '_not_real') self.assertEqual(cm.exception.name, '_not_real')
Frozen_ExecModuleTests, Source_ExecModuleTests = util.test_both(ExecModuleTests,
machinery=machinery) (Frozen_ExecModuleTests,
Source_ExecModuleTests
) = util.test_both(ExecModuleTests, machinery=machinery)
class LoaderTests(abc.LoaderTests): class LoaderTests(abc.LoaderTests):
...@@ -175,8 +177,10 @@ class LoaderTests(abc.LoaderTests): ...@@ -175,8 +177,10 @@ class LoaderTests(abc.LoaderTests):
self.machinery.FrozenImporter.load_module('_not_real') self.machinery.FrozenImporter.load_module('_not_real')
self.assertEqual(cm.exception.name, '_not_real') self.assertEqual(cm.exception.name, '_not_real')
Frozen_LoaderTests, Source_LoaderTests = util.test_both(LoaderTests,
machinery=machinery) (Frozen_LoaderTests,
Source_LoaderTests
) = util.test_both(LoaderTests, machinery=machinery)
class InspectLoaderTests: class InspectLoaderTests:
...@@ -214,8 +218,9 @@ class InspectLoaderTests: ...@@ -214,8 +218,9 @@ class InspectLoaderTests:
method('importlib') method('importlib')
self.assertEqual(cm.exception.name, 'importlib') self.assertEqual(cm.exception.name, 'importlib')
Frozen_ILTests, Source_ILTests = util.test_both(InspectLoaderTests, (Frozen_ILTests,
machinery=machinery) Source_ILTests
) = util.test_both(InspectLoaderTests, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -23,8 +23,10 @@ class SpecLoaderAttributeTests: ...@@ -23,8 +23,10 @@ class SpecLoaderAttributeTests:
module = self.__import__('blah') module = self.__import__('blah')
self.assertEqual(loader, module.__loader__) self.assertEqual(loader, module.__loader__)
Frozen_SpecTests, Source_SpecTests = util.test_both(
SpecLoaderAttributeTests, __import__=util.__import__) (Frozen_SpecTests,
Source_SpecTests
) = util.test_both(SpecLoaderAttributeTests, __import__=util.__import__)
class LoaderMock: class LoaderMock:
...@@ -61,8 +63,9 @@ class LoaderAttributeTests: ...@@ -61,8 +63,9 @@ class LoaderAttributeTests:
self.assertEqual(loader, module.__loader__) self.assertEqual(loader, module.__loader__)
Frozen_Tests, Source_Tests = util.test_both(LoaderAttributeTests, (Frozen_Tests,
__import__=util.__import__) Source_Tests
) = util.test_both(LoaderAttributeTests, __import__=util.__import__)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -69,17 +69,23 @@ class Using__package__: ...@@ -69,17 +69,23 @@ class Using__package__:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
self.__import__('', globals, {}, ['relimport'], 1) self.__import__('', globals, {}, ['relimport'], 1)
class Using__package__PEP302(Using__package__): class Using__package__PEP302(Using__package__):
mock_modules = util.mock_modules mock_modules = util.mock_modules
Frozen_UsingPackagePEP302, Source_UsingPackagePEP302 = util.test_both(
Using__package__PEP302, __import__=util.__import__) (Frozen_UsingPackagePEP302,
Source_UsingPackagePEP302
) = util.test_both(Using__package__PEP302, __import__=util.__import__)
class Using__package__PEP451(Using__package__): class Using__package__PEP451(Using__package__):
mock_modules = util.mock_spec mock_modules = util.mock_spec
Frozen_UsingPackagePEP451, Source_UsingPackagePEP451 = util.test_both(
Using__package__PEP451, __import__=util.__import__) (Frozen_UsingPackagePEP451,
Source_UsingPackagePEP451
) = util.test_both(Using__package__PEP451, __import__=util.__import__)
class Setting__package__: class Setting__package__:
...@@ -94,7 +100,7 @@ class Setting__package__: ...@@ -94,7 +100,7 @@ class Setting__package__:
""" """
__import__ = util.__import__[1] __import__ = util.__import__['Source']
# [top-level] # [top-level]
def test_top_level(self): def test_top_level(self):
......
...@@ -78,15 +78,19 @@ class APITest: ...@@ -78,15 +78,19 @@ class APITest:
class OldAPITests(APITest): class OldAPITests(APITest):
bad_finder_loader = BadLoaderFinder bad_finder_loader = BadLoaderFinder
Frozen_OldAPITests, Source_OldAPITests = util.test_both(
OldAPITests, __import__=util.__import__) (Frozen_OldAPITests,
Source_OldAPITests
) = util.test_both(OldAPITests, __import__=util.__import__)
class SpecAPITests(APITest): class SpecAPITests(APITest):
bad_finder_loader = BadSpecFinderLoader bad_finder_loader = BadSpecFinderLoader
Frozen_SpecAPITests, Source_SpecAPITests = util.test_both(
SpecAPITests, __import__=util.__import__) (Frozen_SpecAPITests,
Source_SpecAPITests
) = util.test_both(SpecAPITests, __import__=util.__import__)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -38,15 +38,17 @@ class UseCache: ...@@ -38,15 +38,17 @@ class UseCache:
self.__import__(name) self.__import__(name)
self.assertEqual(cm.exception.name, name) self.assertEqual(cm.exception.name, name)
Frozen_UseCache, Source_UseCache = util.test_both(
UseCache, __import__=util.__import__) (Frozen_UseCache,
Source_UseCache
) = util.test_both(UseCache, __import__=util.__import__)
class ImportlibUseCache(UseCache, unittest.TestCase): class ImportlibUseCache(UseCache, unittest.TestCase):
# Pertinent only to PEP 302; exec_module() doesn't return a module. # Pertinent only to PEP 302; exec_module() doesn't return a module.
__import__ = util.__import__[1] __import__ = util.__import__['Source']
def create_mock(self, *names, return_=None): def create_mock(self, *names, return_=None):
mock = util.mock_modules(*names) mock = util.mock_modules(*names)
......
...@@ -28,8 +28,10 @@ class ReturnValue: ...@@ -28,8 +28,10 @@ class ReturnValue:
module = self.__import__('pkg.module', fromlist=['attr']) module = self.__import__('pkg.module', fromlist=['attr'])
self.assertEqual(module.__name__, 'pkg.module') self.assertEqual(module.__name__, 'pkg.module')
Frozen_ReturnValue, Source_ReturnValue = util.test_both(
ReturnValue, __import__=util.__import__) (Frozen_ReturnValue,
Source_ReturnValue
) = util.test_both(ReturnValue, __import__=util.__import__)
class HandlingFromlist: class HandlingFromlist:
...@@ -120,8 +122,10 @@ class HandlingFromlist: ...@@ -120,8 +122,10 @@ class HandlingFromlist:
self.assertEqual(module.module1.__name__, 'pkg.module1') self.assertEqual(module.module1.__name__, 'pkg.module1')
self.assertEqual(module.module2.__name__, 'pkg.module2') self.assertEqual(module.module2.__name__, 'pkg.module2')
Frozen_FromList, Source_FromList = util.test_both(
HandlingFromlist, __import__=util.__import__) (Frozen_FromList,
Source_FromList
) = util.test_both(HandlingFromlist, __import__=util.__import__)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -45,8 +45,10 @@ class CallingOrder: ...@@ -45,8 +45,10 @@ class CallingOrder:
self.assertEqual(len(w), 1) self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, ImportWarning)) self.assertTrue(issubclass(w[-1].category, ImportWarning))
Frozen_CallingOrder, Source_CallingOrder = util.test_both(
CallingOrder, __import__=util.__import__) (Frozen_CallingOrder,
Source_CallingOrder
) = util.test_both(CallingOrder, __import__=util.__import__)
class CallSignature: class CallSignature:
...@@ -99,19 +101,25 @@ class CallSignature: ...@@ -99,19 +101,25 @@ class CallSignature:
self.assertEqual(args[0], mod_name) self.assertEqual(args[0], mod_name)
self.assertIs(args[1], path) self.assertIs(args[1], path)
class CallSignaturePEP302(CallSignature): class CallSignaturePEP302(CallSignature):
mock_modules = util.mock_modules mock_modules = util.mock_modules
finder_name = 'find_module' finder_name = 'find_module'
Frozen_CallSignaturePEP302, Source_CallSignaturePEP302 = util.test_both(
CallSignaturePEP302, __import__=util.__import__) (Frozen_CallSignaturePEP302,
Source_CallSignaturePEP302
) = util.test_both(CallSignaturePEP302, __import__=util.__import__)
class CallSignaturePEP451(CallSignature): class CallSignaturePEP451(CallSignature):
mock_modules = util.mock_spec mock_modules = util.mock_spec
finder_name = 'find_spec' finder_name = 'find_spec'
Frozen_CallSignaturePEP451, Source_CallSignaturePEP451 = util.test_both(
CallSignaturePEP451, __import__=util.__import__) (Frozen_CallSignaturePEP451,
Source_CallSignaturePEP451
) = util.test_both(CallSignaturePEP451, __import__=util.__import__)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -101,8 +101,10 @@ class ParentModuleTests: ...@@ -101,8 +101,10 @@ class ParentModuleTests:
finally: finally:
support.unload(subname) support.unload(subname)
Frozen_ParentTests, Source_ParentTests = util.test_both(
ParentModuleTests, __import__=util.__import__) (Frozen_ParentTests,
Source_ParentTests
) = util.test_both(ParentModuleTests, __import__=util.__import__)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -158,8 +158,10 @@ class FinderTests: ...@@ -158,8 +158,10 @@ class FinderTests:
got = self.machinery.PathFinder.find_spec('whatever', [path]) got = self.machinery.PathFinder.find_spec('whatever', [path])
self.assertEqual(got, success_finder.spec) self.assertEqual(got, success_finder.spec)
Frozen_FinderTests, Source_FinderTests = util.test_both(
FinderTests, importlib=importlib, machinery=machinery) (Frozen_FinderTests,
Source_FinderTests
) = util.test_both(FinderTests, importlib=importlib, machinery=machinery)
class PathEntryFinderTests: class PathEntryFinderTests:
...@@ -182,8 +184,10 @@ class PathEntryFinderTests: ...@@ -182,8 +184,10 @@ class PathEntryFinderTests:
path_hooks=[Finder]): path_hooks=[Finder]):
self.machinery.PathFinder.find_spec('importlib') self.machinery.PathFinder.find_spec('importlib')
Frozen_PEFTests, Source_PEFTests = util.test_both(
PathEntryFinderTests, machinery=machinery) (Frozen_PEFTests,
Source_PEFTests
) = util.test_both(PathEntryFinderTests, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -207,8 +207,10 @@ class RelativeImports: ...@@ -207,8 +207,10 @@ class RelativeImports:
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
self.__import__('sys', level=1) self.__import__('sys', level=1)
Frozen_RelativeImports, Source_RelativeImports = util.test_both(
RelativeImports, __import__=util.__import__) (Frozen_RelativeImports,
Source_RelativeImports
) = util.test_both(RelativeImports, __import__=util.__import__)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -62,20 +62,28 @@ class CaseSensitivityTest: ...@@ -62,20 +62,28 @@ class CaseSensitivityTest:
self.assertIsNotNone(insensitive) self.assertIsNotNone(insensitive)
self.assertIn(self.name, insensitive.get_filename(self.name)) self.assertIn(self.name, insensitive.get_filename(self.name))
class CaseSensitivityTestPEP302(CaseSensitivityTest): class CaseSensitivityTestPEP302(CaseSensitivityTest):
def find(self, finder): def find(self, finder):
return finder.find_module(self.name) return finder.find_module(self.name)
Frozen_CaseSensitivityTestPEP302, Source_CaseSensitivityTestPEP302 = util.test_both(
CaseSensitivityTestPEP302, importlib=importlib, machinery=machinery) (Frozen_CaseSensitivityTestPEP302,
Source_CaseSensitivityTestPEP302
) = util.test_both(CaseSensitivityTestPEP302, importlib=importlib,
machinery=machinery)
class CaseSensitivityTestPEP451(CaseSensitivityTest): class CaseSensitivityTestPEP451(CaseSensitivityTest):
def find(self, finder): def find(self, finder):
found = finder.find_spec(self.name) found = finder.find_spec(self.name)
return found.loader if found is not None else found return found.loader if found is not None else found
Frozen_CaseSensitivityTestPEP451, Source_CaseSensitivityTestPEP451 = util.test_both(
CaseSensitivityTestPEP451, importlib=importlib, machinery=machinery) (Frozen_CaseSensitivityTestPEP451,
Source_CaseSensitivityTestPEP451
) = util.test_both(CaseSensitivityTestPEP451, importlib=importlib,
machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -235,9 +235,11 @@ class SimpleTest(abc.LoaderTests): ...@@ -235,9 +235,11 @@ class SimpleTest(abc.LoaderTests):
warnings.simplefilter('ignore', DeprecationWarning) warnings.simplefilter('ignore', DeprecationWarning)
loader.load_module('bad name') loader.load_module('bad name')
Frozen_SimpleTest, Source_SimpleTest = util.test_both(
SimpleTest, importlib=importlib, machinery=machinery, abc=importlib_abc, (Frozen_SimpleTest,
util=importlib_util) Source_SimpleTest
) = util.test_both(SimpleTest, importlib=importlib, machinery=machinery,
abc=importlib_abc, util=importlib_util)
class BadBytecodeTest: class BadBytecodeTest:
...@@ -346,6 +348,7 @@ class BadBytecodeTest: ...@@ -346,6 +348,7 @@ class BadBytecodeTest:
lambda bc: b'\x00\x00\x00\x00' + bc[4:]) lambda bc: b'\x00\x00\x00\x00' + bc[4:])
test('_temp', mapping, bc_path) test('_temp', mapping, bc_path)
class BadBytecodeTestPEP451(BadBytecodeTest): class BadBytecodeTestPEP451(BadBytecodeTest):
def import_(self, file, module_name): def import_(self, file, module_name):
...@@ -354,6 +357,7 @@ class BadBytecodeTestPEP451(BadBytecodeTest): ...@@ -354,6 +357,7 @@ class BadBytecodeTestPEP451(BadBytecodeTest):
module.__spec__ = self.util.spec_from_loader(module_name, loader) module.__spec__ = self.util.spec_from_loader(module_name, loader)
loader.exec_module(module) loader.exec_module(module)
class BadBytecodeTestPEP302(BadBytecodeTest): class BadBytecodeTestPEP302(BadBytecodeTest):
def import_(self, file, module_name): def import_(self, file, module_name):
...@@ -490,21 +494,29 @@ class SourceLoaderBadBytecodeTest: ...@@ -490,21 +494,29 @@ class SourceLoaderBadBytecodeTest:
# Make writable for eventual clean-up. # Make writable for eventual clean-up.
os.chmod(bytecode_path, stat.S_IWUSR) os.chmod(bytecode_path, stat.S_IWUSR)
class SourceLoaderBadBytecodeTestPEP451( class SourceLoaderBadBytecodeTestPEP451(
SourceLoaderBadBytecodeTest, BadBytecodeTestPEP451): SourceLoaderBadBytecodeTest, BadBytecodeTestPEP451):
pass pass
Frozen_SourceBadBytecodePEP451, Source_SourceBadBytecodePEP451 = util.test_both(
SourceLoaderBadBytecodeTestPEP451, importlib=importlib, machinery=machinery, (Frozen_SourceBadBytecodePEP451,
abc=importlib_abc, util=importlib_util) Source_SourceBadBytecodePEP451
) = util.test_both(SourceLoaderBadBytecodeTestPEP451, importlib=importlib,
machinery=machinery, abc=importlib_abc,
util=importlib_util)
class SourceLoaderBadBytecodeTestPEP302( class SourceLoaderBadBytecodeTestPEP302(
SourceLoaderBadBytecodeTest, BadBytecodeTestPEP302): SourceLoaderBadBytecodeTest, BadBytecodeTestPEP302):
pass pass
Frozen_SourceBadBytecodePEP302, Source_SourceBadBytecodePEP302 = util.test_both(
SourceLoaderBadBytecodeTestPEP302, importlib=importlib, machinery=machinery, (Frozen_SourceBadBytecodePEP302,
abc=importlib_abc, util=importlib_util) Source_SourceBadBytecodePEP302
) = util.test_both(SourceLoaderBadBytecodeTestPEP302, importlib=importlib,
machinery=machinery, abc=importlib_abc,
util=importlib_util)
class SourcelessLoaderBadBytecodeTest: class SourcelessLoaderBadBytecodeTest:
...@@ -566,21 +578,29 @@ class SourcelessLoaderBadBytecodeTest: ...@@ -566,21 +578,29 @@ class SourcelessLoaderBadBytecodeTest:
def test_non_code_marshal(self): def test_non_code_marshal(self):
self._test_non_code_marshal(del_source=True) self._test_non_code_marshal(del_source=True)
class SourcelessLoaderBadBytecodeTestPEP451(SourcelessLoaderBadBytecodeTest, class SourcelessLoaderBadBytecodeTestPEP451(SourcelessLoaderBadBytecodeTest,
BadBytecodeTestPEP451): BadBytecodeTestPEP451):
pass pass
Frozen_SourcelessBadBytecodePEP451, Source_SourcelessBadBytecodePEP451 = util.test_both(
SourcelessLoaderBadBytecodeTestPEP451, importlib=importlib, (Frozen_SourcelessBadBytecodePEP451,
machinery=machinery, abc=importlib_abc, util=importlib_util) Source_SourcelessBadBytecodePEP451
) = util.test_both(SourcelessLoaderBadBytecodeTestPEP451, importlib=importlib,
machinery=machinery, abc=importlib_abc,
util=importlib_util)
class SourcelessLoaderBadBytecodeTestPEP302(SourcelessLoaderBadBytecodeTest, class SourcelessLoaderBadBytecodeTestPEP302(SourcelessLoaderBadBytecodeTest,
BadBytecodeTestPEP302): BadBytecodeTestPEP302):
pass pass
Frozen_SourcelessBadBytecodePEP302, Source_SourcelessBadBytecodePEP302 = util.test_both(
SourcelessLoaderBadBytecodeTestPEP302, importlib=importlib, (Frozen_SourcelessBadBytecodePEP302,
machinery=machinery, abc=importlib_abc, util=importlib_util) Source_SourcelessBadBytecodePEP302
) = util.test_both(SourcelessLoaderBadBytecodeTestPEP302, importlib=importlib,
machinery=machinery, abc=importlib_abc,
util=importlib_util)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -195,8 +195,10 @@ class FinderTestsPEP451(FinderTests): ...@@ -195,8 +195,10 @@ class FinderTestsPEP451(FinderTests):
spec = finder.find_spec(name) spec = finder.find_spec(name)
return spec.loader if spec is not None else spec return spec.loader if spec is not None else spec
Frozen_FinderTestsPEP451, Source_FinderTestsPEP451 = util.test_both(
FinderTestsPEP451, machinery=machinery) (Frozen_FinderTestsPEP451,
Source_FinderTestsPEP451
) = util.test_both(FinderTestsPEP451, machinery=machinery)
class FinderTestsPEP420(FinderTests): class FinderTestsPEP420(FinderTests):
...@@ -209,8 +211,10 @@ class FinderTestsPEP420(FinderTests): ...@@ -209,8 +211,10 @@ class FinderTestsPEP420(FinderTests):
loader_portions = finder.find_loader(name) loader_portions = finder.find_loader(name)
return loader_portions[0] if loader_only else loader_portions return loader_portions[0] if loader_only else loader_portions
Frozen_FinderTestsPEP420, Source_FinderTestsPEP420 = util.test_both(
FinderTestsPEP420, machinery=machinery) (Frozen_FinderTestsPEP420,
Source_FinderTestsPEP420
) = util.test_both(FinderTestsPEP420, machinery=machinery)
class FinderTestsPEP302(FinderTests): class FinderTestsPEP302(FinderTests):
...@@ -222,9 +226,10 @@ class FinderTestsPEP302(FinderTests): ...@@ -222,9 +226,10 @@ class FinderTestsPEP302(FinderTests):
warnings.simplefilter("ignore", DeprecationWarning) warnings.simplefilter("ignore", DeprecationWarning)
return finder.find_module(name) return finder.find_module(name)
Frozen_FinderTestsPEP302, Source_FinderTestsPEP302 = util.test_both(
FinderTestsPEP302, machinery=machinery)
(Frozen_FinderTestsPEP302,
Source_FinderTestsPEP302
) = util.test_both(FinderTestsPEP302, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -22,7 +22,10 @@ class PathHookTest: ...@@ -22,7 +22,10 @@ class PathHookTest:
# The empty string represents the cwd. # The empty string represents the cwd.
self.assertTrue(hasattr(self.path_hook()(''), 'find_module')) self.assertTrue(hasattr(self.path_hook()(''), 'find_module'))
Frozen_PathHookTest, Source_PathHooktest = util.test_both(PathHookTest, machinery=machinery)
(Frozen_PathHookTest,
Source_PathHooktest
) = util.test_both(PathHookTest, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -88,6 +88,7 @@ class EncodingTest: ...@@ -88,6 +88,7 @@ class EncodingTest:
with self.assertRaises(SyntaxError): with self.assertRaises(SyntaxError):
self.run_test(source) self.run_test(source)
class EncodingTestPEP451(EncodingTest): class EncodingTestPEP451(EncodingTest):
def load(self, loader): def load(self, loader):
...@@ -96,8 +97,11 @@ class EncodingTestPEP451(EncodingTest): ...@@ -96,8 +97,11 @@ class EncodingTestPEP451(EncodingTest):
loader.exec_module(module) loader.exec_module(module)
return module return module
Frozen_EncodingTestPEP451, Source_EncodingTestPEP451 = util.test_both(
EncodingTestPEP451, machinery=machinery) (Frozen_EncodingTestPEP451,
Source_EncodingTestPEP451
) = util.test_both(EncodingTestPEP451, machinery=machinery)
class EncodingTestPEP302(EncodingTest): class EncodingTestPEP302(EncodingTest):
...@@ -106,8 +110,10 @@ class EncodingTestPEP302(EncodingTest): ...@@ -106,8 +110,10 @@ class EncodingTestPEP302(EncodingTest):
warnings.simplefilter('ignore', DeprecationWarning) warnings.simplefilter('ignore', DeprecationWarning)
return loader.load_module(self.module_name) return loader.load_module(self.module_name)
Frozen_EncodingTestPEP302, Source_EncodingTestPEP302 = util.test_both(
EncodingTestPEP302, machinery=machinery) (Frozen_EncodingTestPEP302,
Source_EncodingTestPEP302
) = util.test_both(EncodingTestPEP302, machinery=machinery)
class LineEndingTest: class LineEndingTest:
...@@ -138,6 +144,7 @@ class LineEndingTest: ...@@ -138,6 +144,7 @@ class LineEndingTest:
def test_lf(self): def test_lf(self):
self.run_test(b'\n') self.run_test(b'\n')
class LineEndingTestPEP451(LineEndingTest): class LineEndingTestPEP451(LineEndingTest):
def load(self, loader, module_name): def load(self, loader, module_name):
...@@ -146,8 +153,11 @@ class LineEndingTestPEP451(LineEndingTest): ...@@ -146,8 +153,11 @@ class LineEndingTestPEP451(LineEndingTest):
loader.exec_module(module) loader.exec_module(module)
return module return module
Frozen_LineEndingTestPEP451, Source_LineEndingTestPEP451 = util.test_both(
LineEndingTestPEP451, machinery=machinery) (Frozen_LineEndingTestPEP451,
Source_LineEndingTestPEP451
) = util.test_both(LineEndingTestPEP451, machinery=machinery)
class LineEndingTestPEP302(LineEndingTest): class LineEndingTestPEP302(LineEndingTest):
...@@ -156,8 +166,10 @@ class LineEndingTestPEP302(LineEndingTest): ...@@ -156,8 +166,10 @@ class LineEndingTestPEP302(LineEndingTest):
warnings.simplefilter('ignore', DeprecationWarning) warnings.simplefilter('ignore', DeprecationWarning)
return loader.load_module(module_name) return loader.load_module(module_name)
Frozen_LineEndingTestPEP302, Source_LineEndingTestPEP302 = util.test_both(
LineEndingTestPEP302, machinery=machinery) (Frozen_LineEndingTestPEP302,
Source_LineEndingTestPEP302
) = util.test_both(LineEndingTestPEP302, machinery=machinery)
if __name__ == '__main__': if __name__ == '__main__':
......
This diff is collapsed.
This diff is collapsed.
from . import util from . import util as test_util
frozen_init, source_init = util.import_importlib('importlib')
frozen_bootstrap = frozen_init._bootstrap init = test_util.import_importlib('importlib')
source_bootstrap = source_init._bootstrap
import sys import sys
import time import time
...@@ -33,13 +32,16 @@ if threading is not None: ...@@ -33,13 +32,16 @@ if threading is not None:
# _release_save() unsupported # _release_save() unsupported
test_release_save_unacquired = None test_release_save_unacquired = None
class Frozen_ModuleLockAsRLockTests(ModuleLockAsRLockTests, lock_tests.RLockTests): LOCK_TYPES = {kind: splitinit._bootstrap._ModuleLock
LockType = frozen_bootstrap._ModuleLock for kind, splitinit in init.items()}
class Source_ModuleLockAsRLockTests(ModuleLockAsRLockTests, lock_tests.RLockTests):
LockType = source_bootstrap._ModuleLock
(Frozen_ModuleLockAsRLockTests,
Source_ModuleLockAsRLockTests
) = test_util.test_both(ModuleLockAsRLockTests, lock_tests.RLockTests,
LockType=LOCK_TYPES)
else: else:
LOCK_TYPES = {}
class Frozen_ModuleLockAsRLockTests(unittest.TestCase): class Frozen_ModuleLockAsRLockTests(unittest.TestCase):
pass pass
...@@ -47,6 +49,7 @@ else: ...@@ -47,6 +49,7 @@ else:
pass pass
@unittest.skipUnless(threading, "threads needed for this test")
class DeadlockAvoidanceTests: class DeadlockAvoidanceTests:
def setUp(self): def setUp(self):
...@@ -106,19 +109,22 @@ class DeadlockAvoidanceTests: ...@@ -106,19 +109,22 @@ class DeadlockAvoidanceTests:
self.assertEqual(results.count((True, False)), 0) self.assertEqual(results.count((True, False)), 0)
self.assertEqual(results.count((True, True)), len(results)) self.assertEqual(results.count((True, True)), len(results))
@unittest.skipUnless(threading, "threads needed for this test")
class Frozen_DeadlockAvoidanceTests(DeadlockAvoidanceTests, unittest.TestCase):
LockType = frozen_bootstrap._ModuleLock
DeadlockError = frozen_bootstrap._DeadlockError
@unittest.skipUnless(threading, "threads needed for this test") DEADLOCK_ERRORS = {kind: splitinit._bootstrap._DeadlockError
class Source_DeadlockAvoidanceTests(DeadlockAvoidanceTests, unittest.TestCase): for kind, splitinit in init.items()}
LockType = source_bootstrap._ModuleLock
DeadlockError = source_bootstrap._DeadlockError (Frozen_DeadlockAvoidanceTests,
Source_DeadlockAvoidanceTests
) = test_util.test_both(DeadlockAvoidanceTests,
LockType=LOCK_TYPES, DeadlockError=DEADLOCK_ERRORS)
class LifetimeTests: class LifetimeTests:
@property
def bootstrap(self):
return self.init._bootstrap
def test_lock_lifetime(self): def test_lock_lifetime(self):
name = "xyzzy" name = "xyzzy"
self.assertNotIn(name, self.bootstrap._module_locks) self.assertNotIn(name, self.bootstrap._module_locks)
...@@ -135,11 +141,10 @@ class LifetimeTests: ...@@ -135,11 +141,10 @@ class LifetimeTests:
self.assertEqual(0, len(self.bootstrap._module_locks), self.assertEqual(0, len(self.bootstrap._module_locks),
self.bootstrap._module_locks) self.bootstrap._module_locks)
class Frozen_LifetimeTests(LifetimeTests, unittest.TestCase):
bootstrap = frozen_bootstrap
class Source_LifetimeTests(LifetimeTests, unittest.TestCase): (Frozen_LifetimeTests,
bootstrap = source_bootstrap Source_LifetimeTests
) = test_util.test_both(LifetimeTests, init=init)
@support.reap_threads @support.reap_threads
......
from . import util from . import util as test_util
frozen_init, source_init = util.import_importlib('importlib') init = test_util.import_importlib('importlib')
frozen_bootstrap = frozen_init._bootstrap machinery = test_util.import_importlib('importlib.machinery')
source_bootstrap = source_init._bootstrap util = test_util.import_importlib('importlib.util')
frozen_machinery, source_machinery = util.import_importlib('importlib.machinery')
frozen_util, source_util = util.import_importlib('importlib.util')
import os.path import os.path
from test.support import CleanImport from test.support import CleanImport
...@@ -52,6 +50,8 @@ class LegacyLoader(TestLoader): ...@@ -52,6 +50,8 @@ class LegacyLoader(TestLoader):
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning) warnings.simplefilter("ignore", DeprecationWarning)
frozen_util = util['Frozen']
@frozen_util.module_for_loader @frozen_util.module_for_loader
def load_module(self, module): def load_module(self, module):
module.ham = self.HAM module.ham = self.HAM
...@@ -221,18 +221,17 @@ class ModuleSpecTests: ...@@ -221,18 +221,17 @@ class ModuleSpecTests:
self.assertEqual(self.loc_spec.cached, 'spam.pyc') self.assertEqual(self.loc_spec.cached, 'spam.pyc')
class Frozen_ModuleSpecTests(ModuleSpecTests, unittest.TestCase): (Frozen_ModuleSpecTests,
util = frozen_util Source_ModuleSpecTests
machinery = frozen_machinery ) = test_util.test_both(ModuleSpecTests, util=util, machinery=machinery)
class Source_ModuleSpecTests(ModuleSpecTests, unittest.TestCase):
util = source_util
machinery = source_machinery
class ModuleSpecMethodsTests: class ModuleSpecMethodsTests:
@property
def bootstrap(self):
return self.init._bootstrap
def setUp(self): def setUp(self):
self.name = 'spam' self.name = 'spam'
self.path = 'spam.py' self.path = 'spam.py'
...@@ -528,20 +527,18 @@ class ModuleSpecMethodsTests: ...@@ -528,20 +527,18 @@ class ModuleSpecMethodsTests:
self.assertIs(installed, loaded) self.assertIs(installed, loaded)
class Frozen_ModuleSpecMethodsTests(ModuleSpecMethodsTests, unittest.TestCase): (Frozen_ModuleSpecMethodsTests,
bootstrap = frozen_bootstrap Source_ModuleSpecMethodsTests
machinery = frozen_machinery ) = test_util.test_both(ModuleSpecMethodsTests, init=init, util=util,
util = frozen_util machinery=machinery)
class Source_ModuleSpecMethodsTests(ModuleSpecMethodsTests, unittest.TestCase):
bootstrap = source_bootstrap
machinery = source_machinery
util = source_util
class ModuleReprTests: class ModuleReprTests:
@property
def bootstrap(self):
return self.init._bootstrap
def setUp(self): def setUp(self):
self.module = type(os)('spam') self.module = type(os)('spam')
self.spec = self.machinery.ModuleSpec('spam', TestLoader()) self.spec = self.machinery.ModuleSpec('spam', TestLoader())
...@@ -625,16 +622,10 @@ class ModuleReprTests: ...@@ -625,16 +622,10 @@ class ModuleReprTests:
self.assertEqual(modrepr, '<module {!r}>'.format('spam')) self.assertEqual(modrepr, '<module {!r}>'.format('spam'))
class Frozen_ModuleReprTests(ModuleReprTests, unittest.TestCase): (Frozen_ModuleReprTests,
bootstrap = frozen_bootstrap Source_ModuleReprTests
machinery = frozen_machinery ) = test_util.test_both(ModuleReprTests, init=init, util=util,
util = frozen_util machinery=machinery)
class Source_ModuleReprTests(ModuleReprTests, unittest.TestCase):
bootstrap = source_bootstrap
machinery = source_machinery
util = source_util
class FactoryTests: class FactoryTests:
...@@ -787,7 +778,7 @@ class FactoryTests: ...@@ -787,7 +778,7 @@ class FactoryTests:
# spec_from_file_location() # spec_from_file_location()
def test_spec_from_file_location_default(self): def test_spec_from_file_location_default(self):
if self.machinery is source_machinery: if self.machinery is machinery['Source']:
raise unittest.SkipTest('not sure why this is breaking...') raise unittest.SkipTest('not sure why this is breaking...')
spec = self.util.spec_from_file_location(self.name, self.path) spec = self.util.spec_from_file_location(self.name, self.path)
...@@ -947,11 +938,6 @@ class FactoryTests: ...@@ -947,11 +938,6 @@ class FactoryTests:
self.assertTrue(spec.has_location) self.assertTrue(spec.has_location)
class Frozen_FactoryTests(FactoryTests, unittest.TestCase): (Frozen_FactoryTests,
util = frozen_util Source_FactoryTests
machinery = frozen_machinery ) = test_util.test_both(FactoryTests, util=util, machinery=machinery)
class Source_FactoryTests(FactoryTests, unittest.TestCase):
util = source_util
machinery = source_machinery
from importlib import util import importlib.util
from . import util as test_util from . import util as test_util
frozen_init, source_init = test_util.import_importlib('importlib') init = test_util.import_importlib('importlib')
frozen_machinery, source_machinery = test_util.import_importlib('importlib.machinery') machinery = test_util.import_importlib('importlib.machinery')
frozen_util, source_util = test_util.import_importlib('importlib.util') util = test_util.import_importlib('importlib.util')
import os import os
import sys import sys
...@@ -32,8 +32,10 @@ class DecodeSourceBytesTests: ...@@ -32,8 +32,10 @@ class DecodeSourceBytesTests:
self.assertEqual(self.util.decode_source(source_bytes), self.assertEqual(self.util.decode_source(source_bytes),
'\n'.join([self.source, self.source])) '\n'.join([self.source, self.source]))
Frozen_DecodeSourceBytesTests, Source_DecodeSourceBytesTests = test_util.test_both(
DecodeSourceBytesTests, util=[frozen_util, source_util]) (Frozen_DecodeSourceBytesTests,
Source_DecodeSourceBytesTests
) = test_util.test_both(DecodeSourceBytesTests, util=util)
class ModuleForLoaderTests: class ModuleForLoaderTests:
...@@ -161,8 +163,10 @@ class ModuleForLoaderTests: ...@@ -161,8 +163,10 @@ class ModuleForLoaderTests:
self.assertIs(module.__loader__, loader) self.assertIs(module.__loader__, loader)
self.assertEqual(module.__package__, name) self.assertEqual(module.__package__, name)
Frozen_ModuleForLoaderTests, Source_ModuleForLoaderTests = test_util.test_both(
ModuleForLoaderTests, util=[frozen_util, source_util]) (Frozen_ModuleForLoaderTests,
Source_ModuleForLoaderTests
) = test_util.test_both(ModuleForLoaderTests, util=util)
class SetPackageTests: class SetPackageTests:
...@@ -222,18 +226,25 @@ class SetPackageTests: ...@@ -222,18 +226,25 @@ class SetPackageTests:
self.assertEqual(wrapped.__name__, fxn.__name__) self.assertEqual(wrapped.__name__, fxn.__name__)
self.assertEqual(wrapped.__qualname__, fxn.__qualname__) self.assertEqual(wrapped.__qualname__, fxn.__qualname__)
Frozen_SetPackageTests, Source_SetPackageTests = test_util.test_both(
SetPackageTests, util=[frozen_util, source_util]) (Frozen_SetPackageTests,
Source_SetPackageTests
) = test_util.test_both(SetPackageTests, util=util)
class SetLoaderTests: class SetLoaderTests:
"""Tests importlib.util.set_loader().""" """Tests importlib.util.set_loader()."""
class DummyLoader: @property
@util.set_loader def DummyLoader(self):
def load_module(self, module): # Set DummyLoader on the class lazily.
return self.module class DummyLoader:
@self.util.set_loader
def load_module(self, module):
return self.module
self.__class__.DummyLoader = DummyLoader
return DummyLoader
def test_no_attribute(self): def test_no_attribute(self):
loader = self.DummyLoader() loader = self.DummyLoader()
...@@ -262,17 +273,10 @@ class SetLoaderTests: ...@@ -262,17 +273,10 @@ class SetLoaderTests:
warnings.simplefilter('ignore', DeprecationWarning) warnings.simplefilter('ignore', DeprecationWarning)
self.assertEqual(42, loader.load_module('blah').__loader__) self.assertEqual(42, loader.load_module('blah').__loader__)
class Frozen_SetLoaderTests(SetLoaderTests, unittest.TestCase):
class DummyLoader:
@frozen_util.set_loader
def load_module(self, module):
return self.module
class Source_SetLoaderTests(SetLoaderTests, unittest.TestCase): (Frozen_SetLoaderTests,
class DummyLoader: Source_SetLoaderTests
@source_util.set_loader ) = test_util.test_both(SetLoaderTests, util=util)
def load_module(self, module):
return self.module
class ResolveNameTests: class ResolveNameTests:
...@@ -307,9 +311,10 @@ class ResolveNameTests: ...@@ -307,9 +311,10 @@ class ResolveNameTests:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
self.util.resolve_name('..bacon', 'spam') self.util.resolve_name('..bacon', 'spam')
Frozen_ResolveNameTests, Source_ResolveNameTests = test_util.test_both(
ResolveNameTests, (Frozen_ResolveNameTests,
util=[frozen_util, source_util]) Source_ResolveNameTests
) = test_util.test_both(ResolveNameTests, util=util)
class FindSpecTests: class FindSpecTests:
...@@ -446,15 +451,10 @@ class FindSpecTests: ...@@ -446,15 +451,10 @@ class FindSpecTests:
self.assertNotIn(fullname, sorted(sys.modules)) self.assertNotIn(fullname, sorted(sys.modules))
class Frozen_FindSpecTests(FindSpecTests, unittest.TestCase): (Frozen_FindSpecTests,
init = frozen_init Source_FindSpecTests
machinery = frozen_machinery ) = test_util.test_both(FindSpecTests, init=init, util=util,
util = frozen_util machinery=machinery)
class Source_FindSpecTests(FindSpecTests, unittest.TestCase):
init = source_init
machinery = source_machinery
util = source_util
class MagicNumberTests: class MagicNumberTests:
...@@ -467,8 +467,10 @@ class MagicNumberTests: ...@@ -467,8 +467,10 @@ class MagicNumberTests:
# The magic number uses \r\n to come out wrong when splitting on lines. # The magic number uses \r\n to come out wrong when splitting on lines.
self.assertTrue(self.util.MAGIC_NUMBER.endswith(b'\r\n')) self.assertTrue(self.util.MAGIC_NUMBER.endswith(b'\r\n'))
Frozen_MagicNumberTests, Source_MagicNumberTests = test_util.test_both(
MagicNumberTests, util=[frozen_util, source_util]) (Frozen_MagicNumberTests,
Source_MagicNumberTests
) = test_util.test_both(MagicNumberTests, util=util)
class PEP3147Tests: class PEP3147Tests:
...@@ -583,9 +585,10 @@ class PEP3147Tests: ...@@ -583,9 +585,10 @@ class PEP3147Tests:
ValueError, self.util.source_from_cache, ValueError, self.util.source_from_cache,
'/foo/bar/foo.cpython-32.foo.pyc') '/foo/bar/foo.cpython-32.foo.pyc')
Frozen_PEP3147Tests, Source_PEP3147Tests = test_util.test_both(
PEP3147Tests, (Frozen_PEP3147Tests,
util=[frozen_util, source_util]) Source_PEP3147Tests
) = test_util.test_both(PEP3147Tests, util=util)
if __name__ == '__main__': if __name__ == '__main__':
......
from . import util from . import util as test_util
frozen_machinery, source_machinery = util.import_importlib('importlib.machinery') machinery = test_util.import_importlib('importlib.machinery')
import sys import sys
import unittest import unittest
...@@ -19,11 +19,6 @@ class WindowsRegistryFinderTests: ...@@ -19,11 +19,6 @@ class WindowsRegistryFinderTests:
self.assertIs(loader, None) self.assertIs(loader, None)
class Frozen_WindowsRegistryFinderTests(WindowsRegistryFinderTests, (Frozen_WindowsRegistryFinderTests,
unittest.TestCase): Source_WindowsRegistryFinderTests
machinery = frozen_machinery ) = test_util.test_both(WindowsRegistryFinderTests, machinery=machinery)
class Source_WindowsRegistryFinderTests(WindowsRegistryFinderTests,
unittest.TestCase):
machinery = source_machinery
...@@ -50,19 +50,36 @@ def import_importlib(module_name): ...@@ -50,19 +50,36 @@ def import_importlib(module_name):
frozen = support.import_fresh_module(module_name) frozen = support.import_fresh_module(module_name)
source = support.import_fresh_module(module_name, fresh=fresh, source = support.import_fresh_module(module_name, fresh=fresh,
blocked=('_frozen_importlib',)) blocked=('_frozen_importlib',))
return {'Frozen': frozen, 'Source': source}
def specialize_class(cls, kind, base=None, **kwargs):
# XXX Support passing in submodule names--load (and cache) them?
# That would clean up the test modules a bit more.
if base is None:
base = unittest.TestCase
elif not isinstance(base, type):
base = base[kind]
name = '{}_{}'.format(kind, cls.__name__)
bases = (cls, base)
specialized = types.new_class(name, bases)
specialized.__module__ = cls.__module__
specialized._NAME = cls.__name__
specialized._KIND = kind
for attr, values in kwargs.items():
value = values[kind]
setattr(specialized, attr, value)
return specialized
def split_frozen(cls, base=None, **kwargs):
frozen = specialize_class(cls, 'Frozen', base, **kwargs)
source = specialize_class(cls, 'Source', base, **kwargs)
return frozen, source return frozen, source
def test_both(test_class, **kwargs): def test_both(test_class, base=None, **kwargs):
frozen_tests = types.new_class('Frozen_'+test_class.__name__, return split_frozen(test_class, base, **kwargs)
(test_class, unittest.TestCase))
source_tests = types.new_class('Source_'+test_class.__name__,
(test_class, unittest.TestCase))
frozen_tests.__module__ = source_tests.__module__ = test_class.__module__
for attr, (frozen_value, source_value) in kwargs.items():
setattr(frozen_tests, attr, frozen_value)
setattr(source_tests, attr, source_value)
return frozen_tests, source_tests
CASE_INSENSITIVE_FS = True CASE_INSENSITIVE_FS = True
...@@ -75,8 +92,9 @@ if sys.platform not in ('win32', 'cygwin'): ...@@ -75,8 +92,9 @@ if sys.platform not in ('win32', 'cygwin'):
if not os.path.exists(changed_name): if not os.path.exists(changed_name):
CASE_INSENSITIVE_FS = False CASE_INSENSITIVE_FS = False
_, source_importlib = import_importlib('importlib') source_importlib = import_importlib('importlib')['Source']
__import__ = staticmethod(builtins.__import__), staticmethod(source_importlib.__import__) __import__ = {'Frozen': staticmethod(builtins.__import__),
'Source': staticmethod(source_importlib.__import__)}
def case_insensitive_tests(test): def case_insensitive_tests(test):
......
...@@ -496,6 +496,8 @@ Tests ...@@ -496,6 +496,8 @@ Tests
- Issue #21097: Move test_namespace_pkgs into test_importlib. - Issue #21097: Move test_namespace_pkgs into test_importlib.
- Issue #21503: Use test_both() consistently in test_importlib.
- Issue #20939: Avoid various network test failures due to new - Issue #20939: Avoid various network test failures due to new
redirect of http://www.python.org/ to https://www.python.org: redirect of http://www.python.org/ to https://www.python.org:
use http://www.example.com instead. use http://www.example.com instead.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment