mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
Move import semantic util code to importlib.test.import_.util.
This commit is contained in:
parent
bcb26c53c0
commit
d720b36248
10 changed files with 99 additions and 92 deletions
33
Lib/importlib/test/import_/util.py
Normal file
33
Lib/importlib/test/import_/util.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import functools
|
||||
import importlib
|
||||
|
||||
|
||||
using___import__ = False
|
||||
|
||||
|
||||
def import_(*args, **kwargs):
|
||||
"""Delegate to allow for injecting different implementations of import."""
|
||||
if using___import__:
|
||||
return __import__(*args, **kwargs)
|
||||
return importlib.Import()(*args, **kwargs)
|
||||
|
||||
|
||||
def importlib_only(fxn):
|
||||
"""Decorator to mark which tests are not supported by the current
|
||||
implementation of __import__()."""
|
||||
def inner(*args, **kwargs):
|
||||
if using___import__:
|
||||
return
|
||||
else:
|
||||
return fxn(*args, **kwargs)
|
||||
functools.update_wrapper(inner, fxn)
|
||||
return inner
|
||||
|
||||
|
||||
def mock_path_hook(*entries, importer):
|
||||
"""A mock sys.path_hooks entry."""
|
||||
def hook(entry):
|
||||
if entry not in entries:
|
||||
raise ImportError
|
||||
return importer
|
||||
return hook
|
||||
Loading…
Add table
Add a link
Reference in a new issue