Issue #14605: Expose importlib.abc.FileLoader and

importlib.machinery.(FileFinder, SourceFileLoader,
_SourcelessFileLoader, ExtensionFileLoader).

This exposes all of importlib's mechanisms that will become public on
the sys module.
This commit is contained in:
Brett Cannon 2012-04-22 19:58:33 -04:00
parent 8c5e920ae3
commit 938d44d59c
17 changed files with 3246 additions and 3076 deletions

View file

@ -1,3 +1,4 @@
import imp
import sys
from test import support
import unittest
@ -13,8 +14,10 @@ class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
good_name = ext_util.NAME
bad_name = good_name.upper()
assert good_name != bad_name
finder = _bootstrap._FileFinder(ext_util.PATH,
_bootstrap._ExtensionFinderDetails())
finder = _bootstrap.FileFinder(ext_util.PATH,
(_bootstrap.ExtensionFileLoader,
_bootstrap._suffix_list(imp.C_EXTENSION),
False))
return finder.find_module(bad_name)
def test_case_sensitive(self):

View file

@ -2,6 +2,7 @@ from importlib import _bootstrap
from .. import abc
from . import util
import imp
import unittest
class FinderTests(abc.FinderTests):
@ -9,8 +10,10 @@ class FinderTests(abc.FinderTests):
"""Test the finder for extension modules."""
def find_module(self, fullname):
importer = _bootstrap._FileFinder(util.PATH,
_bootstrap._ExtensionFinderDetails())
importer = _bootstrap.FileFinder(util.PATH,
(_bootstrap.ExtensionFileLoader,
_bootstrap._suffix_list(imp.C_EXTENSION),
False))
return importer.find_module(fullname)
def test_module(self):

View file

@ -12,7 +12,7 @@ class LoaderTests(abc.LoaderTests):
"""Test load_module() for extension modules."""
def load_module(self, fullname):
loader = _bootstrap._ExtensionFileLoader(ext_util.NAME,
loader = _bootstrap.ExtensionFileLoader(ext_util.NAME,
ext_util.FILEPATH)
return loader.load_module(fullname)
@ -25,7 +25,7 @@ class LoaderTests(abc.LoaderTests):
self.assertEqual(getattr(module, attr), value)
self.assertTrue(ext_util.NAME in sys.modules)
self.assertTrue(isinstance(module.__loader__,
_bootstrap._ExtensionFileLoader))
_bootstrap.ExtensionFileLoader))
def test_package(self):
# Extensions are not found in packages.

View file

@ -14,7 +14,8 @@ class PathHookTests(unittest.TestCase):
# XXX Should it only work for directories containing an extension module?
def hook(self, entry):
return _bootstrap._file_path_hook(entry)
return _bootstrap.FileFinder.path_hook((_bootstrap.ExtensionFileLoader,
_bootstrap._suffix_list(imp.C_EXTENSION), False))(entry)
def test_success(self):
# Path hook should handle a directory where a known extension module