| 1 | n/a | import functools |
|---|
| 2 | n/a | import importlib |
|---|
| 3 | n/a | import unittest |
|---|
| 4 | n/a | |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | using___import__ = False |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | |
|---|
| 9 | n/a | def import_(*args, **kwargs): |
|---|
| 10 | n/a | """Delegate to allow for injecting different implementations of import.""" |
|---|
| 11 | n/a | if using___import__: |
|---|
| 12 | n/a | return __import__(*args, **kwargs) |
|---|
| 13 | n/a | else: |
|---|
| 14 | n/a | return importlib.__import__(*args, **kwargs) |
|---|
| 15 | n/a | |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | def importlib_only(fxn): |
|---|
| 18 | n/a | """Decorator to skip a test if using __builtins__.__import__.""" |
|---|
| 19 | n/a | return unittest.skipIf(using___import__, "importlib-specific test")(fxn) |
|---|
| 20 | n/a | |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | def mock_path_hook(*entries, importer): |
|---|
| 23 | n/a | """A mock sys.path_hooks entry.""" |
|---|
| 24 | n/a | def hook(entry): |
|---|
| 25 | n/a | if entry not in entries: |
|---|
| 26 | n/a | raise ImportError |
|---|
| 27 | n/a | return importer |
|---|
| 28 | n/a | return hook |
|---|