Skip to content

Commit 23d6c10

Browse files
committedMar 20, 2024
Add compatibility shims for working with cpython fixtures.
1 parent a8ec379 commit 23d6c10

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
 

‎jaraco/test/cpython.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Compatibility shims for getting stuff from test.support across
3+
Python versions (for compatibility with Python 3.9 and earlier).
4+
5+
>>> os_helper = try_import('os_helper') or from_test_support('temp_dir')
6+
>>> os_helper.temp_dir
7+
<function temp_dir at ...>
8+
"""
9+
10+
import importlib
11+
import types
12+
13+
from jaraco.context import suppress
14+
from jaraco.collections import Projection
15+
16+
17+
def from_test_support(*names):
18+
"""
19+
Return a SimpleNamespace of names from test.support.
20+
21+
>>> support = from_test_support('swap_item')
22+
>>> support.swap_item
23+
<function swap_item at ...>
24+
"""
25+
import test.support
26+
27+
return types.SimpleNamespace(**Projection(names, vars(test.support)))
28+
29+
30+
@suppress(ImportError)
31+
def try_import(name):
32+
"""
33+
Attempt to import a submodule of test.support; return None if missing.
34+
"""
35+
return importlib.import_module(f'test.support.{name}')

‎setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ python_requires = >=3.8
1919
install_requires =
2020
jaraco.functools
2121
jaraco.context
22+
jaraco.collections
2223

2324
[options.extras_require]
2425
testing =

0 commit comments

Comments
 (0)