-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compatibility shims for working with cpython fixtures.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Compatibility shims for getting stuff from test.support across | ||
Python versions (for compatibility with Python 3.9 and earlier). | ||
>>> os_helper = try_import('os_helper') or from_test_support('temp_dir') | ||
>>> os_helper.temp_dir | ||
<function temp_dir at ...> | ||
""" | ||
|
||
import importlib | ||
import types | ||
|
||
from jaraco.context import suppress | ||
from jaraco.collections import Projection | ||
|
||
|
||
def from_test_support(*names): | ||
""" | ||
Return a SimpleNamespace of names from test.support. | ||
>>> support = from_test_support('swap_item') | ||
>>> support.swap_item | ||
<function swap_item at ...> | ||
""" | ||
import test.support | ||
|
||
return types.SimpleNamespace(**Projection(names, vars(test.support))) | ||
|
||
|
||
@suppress(ImportError) | ||
def try_import(name): | ||
""" | ||
Attempt to import a submodule of test.support; return None if missing. | ||
""" | ||
return importlib.import_module(f'test.support.{name}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters