2009-02-01 00:28:04 -04:00
|
|
|
import functools
|
2009-02-06 21:15:27 -04:00
|
|
|
import importlib._bootstrap
|
2009-02-01 00:28:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
using___import__ = False
|
|
|
|
|
|
|
|
|
|
|
|
def import_(*args, **kwargs):
|
|
|
|
"""Delegate to allow for injecting different implementations of import."""
|
|
|
|
if using___import__:
|
|
|
|
return __import__(*args, **kwargs)
|
2009-02-06 21:15:27 -04:00
|
|
|
#return importlib.Import()(*args, **kwargs)
|
|
|
|
return importlib._bootstrap._import(*args, **kwargs)
|
2009-02-01 00:28:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
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
|