summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-08-10 17:47:54 (GMT)
committerBrett Cannon <brett@python.org>2012-08-10 17:47:54 (GMT)
commitac9f2f3de31787a016a1220b304db388dc1705e9 (patch)
tree781ab74268b6ca9c6ab18ec71d0c1b0aa7a6d9c9 /Lib/test/test_importlib
parentf4dc9204cc406ab41c2d643c1a64375a6a2954e5 (diff)
downloadcpython-ac9f2f3de31787a016a1220b304db388dc1705e9.zip
cpython-ac9f2f3de31787a016a1220b304db388dc1705e9.tar.gz
cpython-ac9f2f3de31787a016a1220b304db388dc1705e9.tar.bz2
Issue #15576: Allow extension modules to be a package's __init__
module again. Also took the opportunity to stop accidentally exporting _imp.extension_suffixes() as public.
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r--Lib/test/test_importlib/extension/test_case_sensitivity.py3
-rw-r--r--Lib/test/test_importlib/extension/test_finder.py16
-rw-r--r--Lib/test/test_importlib/extension/test_loader.py12
-rw-r--r--Lib/test/test_importlib/extension/test_path_hook.py6
-rw-r--r--Lib/test/test_importlib/source/test_case_sensitivity.py6
-rw-r--r--Lib/test/test_importlib/source/test_finder.py8
-rw-r--r--Lib/test/test_importlib/source/test_path_hook.py2
7 files changed, 27 insertions, 26 deletions
diff --git a/Lib/test/test_importlib/extension/test_case_sensitivity.py b/Lib/test/test_importlib/extension/test_case_sensitivity.py
index bdc21e7..76c53e4 100644
--- a/Lib/test/test_importlib/extension/test_case_sensitivity.py
+++ b/Lib/test/test_importlib/extension/test_case_sensitivity.py
@@ -16,8 +16,7 @@ class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
assert good_name != bad_name
finder = _bootstrap.FileFinder(ext_util.PATH,
(_bootstrap.ExtensionFileLoader,
- imp.extension_suffixes(),
- False))
+ _bootstrap.EXTENSION_SUFFIXES))
return finder.find_module(bad_name)
def test_case_sensitive(self):
diff --git a/Lib/test/test_importlib/extension/test_finder.py b/Lib/test/test_importlib/extension/test_finder.py
index 1c60292..a63cfdb 100644
--- a/Lib/test/test_importlib/extension/test_finder.py
+++ b/Lib/test/test_importlib/extension/test_finder.py
@@ -1,8 +1,7 @@
-from importlib import _bootstrap
+from importlib import machinery
from .. import abc
from . import util
-import imp
import unittest
class FinderTests(abc.FinderTests):
@@ -10,17 +9,16 @@ class FinderTests(abc.FinderTests):
"""Test the finder for extension modules."""
def find_module(self, fullname):
- importer = _bootstrap.FileFinder(util.PATH,
- (_bootstrap.ExtensionFileLoader,
- imp.extension_suffixes(),
- False))
+ importer = machinery.FileFinder(util.PATH,
+ (machinery.ExtensionFileLoader,
+ machinery.EXTENSION_SUFFIXES))
return importer.find_module(fullname)
def test_module(self):
self.assertTrue(self.find_module(util.NAME))
def test_package(self):
- # Extension modules cannot be an __init__ for a package.
+ # No extension module as an __init__ available for testing.
pass
def test_module_in_package(self):
@@ -28,7 +26,7 @@ class FinderTests(abc.FinderTests):
pass
def test_package_in_package(self):
- # Extension modules cannot be an __init__ for a package.
+ # No extension module as an __init__ available for testing.
pass
def test_package_over_module(self):
@@ -38,8 +36,6 @@ class FinderTests(abc.FinderTests):
def test_failure(self):
self.assertIsNone(self.find_module('asdfjkl;'))
- # XXX Raise an exception if someone tries to use the 'path' argument?
-
def test_main():
from test.support import run_unittest
diff --git a/Lib/test/test_importlib/extension/test_loader.py b/Lib/test/test_importlib/extension/test_loader.py
index 917843f..ca5af20 100644
--- a/Lib/test/test_importlib/extension/test_loader.py
+++ b/Lib/test/test_importlib/extension/test_loader.py
@@ -3,6 +3,7 @@ from . import util as ext_util
from .. import abc
from .. import util
+import os.path
import sys
import unittest
@@ -38,11 +39,11 @@ class LoaderTests(abc.LoaderTests):
machinery.ExtensionFileLoader)
def test_package(self):
- # Extensions are not found in packages.
+ # No extension module as __init__ available for testing.
pass
def test_lacking_parent(self):
- # Extensions are not found in packages.
+ # No extension module in a package available for testing.
pass
def test_module_reuse(self):
@@ -61,6 +62,13 @@ class LoaderTests(abc.LoaderTests):
self.load_module(name)
self.assertEqual(cm.exception.name, name)
+ def test_is_package(self):
+ self.assertFalse(self.loader.is_package(ext_util.NAME))
+ for suffix in machinery.EXTENSION_SUFFIXES:
+ path = os.path.join('some', 'path', 'pkg', '__init__' + suffix)
+ loader = machinery.ExtensionFileLoader('pkg', path)
+ self.assertTrue(loader.is_package('pkg'))
+
def test_main():
from test.support import run_unittest
diff --git a/Lib/test/test_importlib/extension/test_path_hook.py b/Lib/test/test_importlib/extension/test_path_hook.py
index 129e6e2..1d969a1 100644
--- a/Lib/test/test_importlib/extension/test_path_hook.py
+++ b/Lib/test/test_importlib/extension/test_path_hook.py
@@ -1,4 +1,4 @@
-from importlib import _bootstrap
+from importlib import machinery
from . import util
import collections
@@ -14,8 +14,8 @@ class PathHookTests(unittest.TestCase):
# XXX Should it only work for directories containing an extension module?
def hook(self, entry):
- return _bootstrap.FileFinder.path_hook((_bootstrap.ExtensionFileLoader,
- imp.extension_suffixes(), False))(entry)
+ return machinery.FileFinder.path_hook((machinery.ExtensionFileLoader,
+ machinery.EXTENSION_SUFFIXES))(entry)
def test_success(self):
# Path hook should handle a directory where a known extension module
diff --git a/Lib/test/test_importlib/source/test_case_sensitivity.py b/Lib/test/test_importlib/source/test_case_sensitivity.py
index 21a4378..241173f 100644
--- a/Lib/test/test_importlib/source/test_case_sensitivity.py
+++ b/Lib/test/test_importlib/source/test_case_sensitivity.py
@@ -23,11 +23,9 @@ class CaseSensitivityTest(unittest.TestCase):
def find(self, path):
finder = machinery.FileFinder(path,
(machinery.SourceFileLoader,
- machinery.SOURCE_SUFFIXES,
- True),
+ machinery.SOURCE_SUFFIXES),
(machinery.SourcelessFileLoader,
- machinery.BYTECODE_SUFFIXES,
- True))
+ machinery.BYTECODE_SUFFIXES))
return finder.find_module(self.name)
def sensitivity_test(self):
diff --git a/Lib/test/test_importlib/source/test_finder.py b/Lib/test/test_importlib/source/test_finder.py
index fa5d356..40905eb 100644
--- a/Lib/test/test_importlib/source/test_finder.py
+++ b/Lib/test/test_importlib/source/test_finder.py
@@ -37,9 +37,9 @@ class FinderTests(abc.FinderTests):
def import_(self, root, module):
loader_details = [(machinery.SourceFileLoader,
- machinery.SOURCE_SUFFIXES, True),
+ machinery.SOURCE_SUFFIXES),
(machinery.SourcelessFileLoader,
- machinery.BYTECODE_SUFFIXES, True)]
+ machinery.BYTECODE_SUFFIXES)]
finder = machinery.FileFinder(root, *loader_details)
return finder.find_module(module)
@@ -120,7 +120,7 @@ class FinderTests(abc.FinderTests):
def test_empty_string_for_dir(self):
# The empty string from sys.path means to search in the cwd.
finder = machinery.FileFinder('', (machinery.SourceFileLoader,
- machinery.SOURCE_SUFFIXES, True))
+ machinery.SOURCE_SUFFIXES))
with open('mod.py', 'w') as file:
file.write("# test file for importlib")
try:
@@ -132,7 +132,7 @@ class FinderTests(abc.FinderTests):
def test_invalidate_caches(self):
# invalidate_caches() should reset the mtime.
finder = machinery.FileFinder('', (machinery.SourceFileLoader,
- machinery.SOURCE_SUFFIXES, True))
+ machinery.SOURCE_SUFFIXES))
finder._path_mtime = 42
finder.invalidate_caches()
self.assertEqual(finder._path_mtime, -1)
diff --git a/Lib/test/test_importlib/source/test_path_hook.py b/Lib/test/test_importlib/source/test_path_hook.py
index 54c0699..6a78792 100644
--- a/Lib/test/test_importlib/source/test_path_hook.py
+++ b/Lib/test/test_importlib/source/test_path_hook.py
@@ -11,7 +11,7 @@ class PathHookTest(unittest.TestCase):
def path_hook(self):
return machinery.FileFinder.path_hook((machinery.SourceFileLoader,
- machinery.SOURCE_SUFFIXES, True))
+ machinery.SOURCE_SUFFIXES))
def test_success(self):
with source_util.create_modules('dummy') as mapping: