mirror of https://github.com/python/cpython
Issue #16803: Move test.test_importlib.extension to use both frozen and source importlib code
This commit is contained in:
parent
6a4cbc00ab
commit
e38b0544c4
|
@ -1,23 +1,25 @@
|
|||
from importlib import _bootstrap
|
||||
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
|
||||
|
||||
frozen_machinery, source_machinery = util.import_importlib('importlib.machinery')
|
||||
|
||||
|
||||
@unittest.skipIf(ext_util.FILENAME is None, '_testcapi not available')
|
||||
@util.case_insensitive_tests
|
||||
class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
|
||||
class ExtensionModuleCaseSensitivityTest:
|
||||
|
||||
def find_module(self):
|
||||
good_name = ext_util.NAME
|
||||
bad_name = good_name.upper()
|
||||
assert good_name != bad_name
|
||||
finder = machinery.FileFinder(ext_util.PATH,
|
||||
(machinery.ExtensionFileLoader,
|
||||
machinery.EXTENSION_SUFFIXES))
|
||||
finder = self.machinery.FileFinder(ext_util.PATH,
|
||||
(self.machinery.ExtensionFileLoader,
|
||||
self.machinery.EXTENSION_SUFFIXES))
|
||||
return finder.find_module(bad_name)
|
||||
|
||||
def test_case_sensitive(self):
|
||||
|
@ -38,14 +40,10 @@ class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
|
|||
loader = self.find_module()
|
||||
self.assertTrue(hasattr(loader, 'load_module'))
|
||||
|
||||
|
||||
|
||||
|
||||
def test_main():
|
||||
if ext_util.FILENAME is None:
|
||||
return
|
||||
support.run_unittest(ExtensionModuleCaseSensitivityTest)
|
||||
Frozen_ExtensionCaseSensitivity, Source_ExtensionCaseSensitivity = util.test_both(
|
||||
ExtensionModuleCaseSensitivityTest,
|
||||
machinery=[frozen_machinery, source_machinery])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
unittest.main()
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
from importlib import machinery
|
||||
from .. import abc
|
||||
from .. import util as test_util
|
||||
from . import util
|
||||
|
||||
machinery = test_util.import_importlib('importlib.machinery')
|
||||
|
||||
import unittest
|
||||
|
||||
class FinderTests(unittest.TestCase, abc.FinderTests):
|
||||
|
||||
class FinderTests(abc.FinderTests):
|
||||
|
||||
"""Test the finder for extension modules."""
|
||||
|
||||
def find_module(self, fullname):
|
||||
importer = machinery.FileFinder(util.PATH,
|
||||
(machinery.ExtensionFileLoader,
|
||||
machinery.EXTENSION_SUFFIXES))
|
||||
importer = self.machinery.FileFinder(util.PATH,
|
||||
(self.machinery.ExtensionFileLoader,
|
||||
self.machinery.EXTENSION_SUFFIXES))
|
||||
return importer.find_module(fullname)
|
||||
|
||||
def test_module(self):
|
||||
|
@ -36,11 +39,9 @@ class FinderTests(unittest.TestCase, abc.FinderTests):
|
|||
def test_failure(self):
|
||||
self.assertIsNone(self.find_module('asdfjkl;'))
|
||||
|
||||
|
||||
def test_main():
|
||||
from test.support import run_unittest
|
||||
run_unittest(FinderTests)
|
||||
Frozen_FinderTests, Source_FinderTests = test_util.test_both(
|
||||
FinderTests, machinery=machinery)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
unittest.main()
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
from importlib import machinery
|
||||
from . import util as ext_util
|
||||
from .. import abc
|
||||
from .. import util
|
||||
|
||||
machinery = util.import_importlib('importlib.machinery')
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
class LoaderTests(unittest.TestCase, abc.LoaderTests):
|
||||
class LoaderTests(abc.LoaderTests):
|
||||
|
||||
"""Test load_module() for extension modules."""
|
||||
|
||||
def setUp(self):
|
||||
self.loader = machinery.ExtensionFileLoader(ext_util.NAME,
|
||||
ext_util.FILEPATH)
|
||||
self.loader = self.machinery.ExtensionFileLoader(ext_util.NAME,
|
||||
ext_util.FILEPATH)
|
||||
|
||||
def load_module(self, fullname):
|
||||
return self.loader.load_module(fullname)
|
||||
|
@ -36,7 +37,7 @@ class LoaderTests(unittest.TestCase, abc.LoaderTests):
|
|||
self.assertEqual(getattr(module, attr), value)
|
||||
self.assertIn(ext_util.NAME, sys.modules)
|
||||
self.assertIsInstance(module.__loader__,
|
||||
machinery.ExtensionFileLoader)
|
||||
self.machinery.ExtensionFileLoader)
|
||||
|
||||
def test_package(self):
|
||||
# No extension module as __init__ available for testing.
|
||||
|
@ -64,16 +65,15 @@ class LoaderTests(unittest.TestCase, abc.LoaderTests):
|
|||
|
||||
def test_is_package(self):
|
||||
self.assertFalse(self.loader.is_package(ext_util.NAME))
|
||||
for suffix in machinery.EXTENSION_SUFFIXES:
|
||||
for suffix in self.machinery.EXTENSION_SUFFIXES:
|
||||
path = os.path.join('some', 'path', 'pkg', '__init__' + suffix)
|
||||
loader = machinery.ExtensionFileLoader('pkg', path)
|
||||
loader = self.machinery.ExtensionFileLoader('pkg', path)
|
||||
self.assertTrue(loader.is_package('pkg'))
|
||||
|
||||
Frozen_LoaderTests, Source_LoaderTests = util.test_both(
|
||||
LoaderTests, machinery=machinery)
|
||||
|
||||
def test_main():
|
||||
from test.support import run_unittest
|
||||
run_unittest(LoaderTests)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
unittest.main()
|
||||
|
|
|
@ -1,31 +1,32 @@
|
|||
from importlib import machinery
|
||||
from .. import util as test_util
|
||||
from . import util
|
||||
|
||||
machinery = test_util.import_importlib('importlib.machinery')
|
||||
|
||||
import collections
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
class PathHookTests(unittest.TestCase):
|
||||
class PathHookTests:
|
||||
|
||||
"""Test the path hook for extension modules."""
|
||||
# XXX Should it only succeed for pre-existing directories?
|
||||
# XXX Should it only work for directories containing an extension module?
|
||||
|
||||
def hook(self, entry):
|
||||
return machinery.FileFinder.path_hook((machinery.ExtensionFileLoader,
|
||||
machinery.EXTENSION_SUFFIXES))(entry)
|
||||
return self.machinery.FileFinder.path_hook(
|
||||
(self.machinery.ExtensionFileLoader,
|
||||
self.machinery.EXTENSION_SUFFIXES))(entry)
|
||||
|
||||
def test_success(self):
|
||||
# Path hook should handle a directory where a known extension module
|
||||
# exists.
|
||||
self.assertTrue(hasattr(self.hook(util.PATH), 'find_module'))
|
||||
|
||||
|
||||
def test_main():
|
||||
from test.support import run_unittest
|
||||
run_unittest(PathHookTests)
|
||||
Frozen_PathHooksTests, Source_PathHooksTests = test_util.test_both(
|
||||
PathHookTests, machinery=machinery)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue