Skip to content

Commit

Permalink
Add compatibility shims for working with cpython fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 20, 2024
1 parent a8ec379 commit 2b76fe1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions jaraco/test/cpython.py
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('skip_if_buildbot')
>>> support.skip_if_buildbot
<function skip_if_buildbot at ...>
"""
import test.support

return types.SimpleNamespace(**Projection(names, vars(test.support)))


@suppress(ImportError)
def try_import(name):
"""
Attempt to
"""
return importlib.import_module(f'test.support.{name}')
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ python_requires = >=3.8
install_requires =
jaraco.functools
jaraco.context
jaraco.collections

[options.extras_require]
testing =
Expand Down

0 comments on commit 2b76fe1

Please sign in to comment.