2009-02-01 04:28:04 +00:00
|
|
|
import functools
|
2009-08-27 23:44:18 +00:00
|
|
|
import importlib
|
2009-02-07 01:15:27 +00:00
|
|
|
import importlib._bootstrap
|
2009-08-27 23:44:18 +00:00
|
|
|
import unittest
|
2009-02-01 04:28:04 +00: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-15 05:48:13 +00:00
|
|
|
else:
|
2009-08-30 18:40:23 +00:00
|
|
|
return importlib.__import__(*args, **kwargs)
|
2009-02-01 04:28:04 +00:00
|
|
|
|
|
|
|
|
|
2009-08-30 18:59:21 +00:00
|
|
|
def importlib_only(fxn):
|
|
|
|
|
"""Decorator to skip a test if using __builtins__.__import__."""
|
|
|
|
|
return unittest.skipIf(using___import__, "importlib-specific test")(fxn)
|
2009-02-01 04:28:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|