summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test/import_/util.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-02-01 04:28:04 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-02-01 04:28:04 (GMT)
commitd720b362486cc0e89f2b05a7d1473692d9788303 (patch)
tree16e57c9cebbf4107119989264bc41e1da28e65fb /Lib/importlib/test/import_/util.py
parentbcb26c53c095c7bcd0e5415088e25dbd27f12592 (diff)
downloadcpython-d720b362486cc0e89f2b05a7d1473692d9788303.zip
cpython-d720b362486cc0e89f2b05a7d1473692d9788303.tar.gz
cpython-d720b362486cc0e89f2b05a7d1473692d9788303.tar.bz2
Move import semantic util code to importlib.test.import_.util.
Diffstat (limited to 'Lib/importlib/test/import_/util.py')
-rw-r--r--Lib/importlib/test/import_/util.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/importlib/test/import_/util.py b/Lib/importlib/test/import_/util.py
new file mode 100644
index 0000000..3481b99
--- /dev/null
+++ b/Lib/importlib/test/import_/util.py
@@ -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