mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
Add initial implementation of importlib. See the NOTES files for what is
planned for the package. There are no docs yet, but they are coming once the API for the first new function, importlib.import_module() is finalized.
This commit is contained in:
parent
458ad47a2c
commit
23cbd8a656
35 changed files with 3360 additions and 0 deletions
50
Lib/importlib/test/extension/test_path_hook.py
Normal file
50
Lib/importlib/test/extension/test_path_hook.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import importlib
|
||||
|
||||
import collections
|
||||
import imp
|
||||
from os import path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
PATH = None
|
||||
EXT = None
|
||||
FILENAME = None
|
||||
NAME = '_testcapi'
|
||||
_file_exts = [x[0] for x in imp.get_suffixes() if x[2] == imp.C_EXTENSION]
|
||||
try:
|
||||
for PATH in sys.path:
|
||||
for EXT in _file_exts:
|
||||
FILENAME = NAME + EXT
|
||||
FILEPATH = path.join(PATH, FILENAME)
|
||||
if path.exists(path.join(PATH, FILENAME)):
|
||||
raise StopIteration
|
||||
else:
|
||||
PATH = EXT = FILENAME = FILEPATH = None
|
||||
except StopIteration:
|
||||
pass
|
||||
del _file_exts
|
||||
|
||||
|
||||
class PathHookTests(unittest.TestCase):
|
||||
|
||||
"""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 importlib.ExtensionFileImporter(entry)
|
||||
|
||||
def test_success(self):
|
||||
# Path hook should handle a directory where a known extension module
|
||||
# exists.
|
||||
self.assert_(hasattr(self.hook(PATH), 'find_module'))
|
||||
|
||||
|
||||
def test_main():
|
||||
from test.support import run_unittest
|
||||
run_unittest(PathHookTests)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue