From a8892ae076dd24f129e51125f28b9a9abf846e8f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 6 Mar 2024 16:07:41 -0500 Subject: [PATCH] Extract 'from_test_support' helper. --- importlib_resources/tests/compat/py39.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/importlib_resources/tests/compat/py39.py b/importlib_resources/tests/compat/py39.py index a1e1e2d..93fb699 100644 --- a/importlib_resources/tests/compat/py39.py +++ b/importlib_resources/tests/compat/py39.py @@ -8,21 +8,27 @@ from jaraco.collections import Projection +def from_test_support(*names): + """ + Return a SimpleNamespace of names from test.support. + """ + import test.support + + return types.SimpleNamespace(**Projection(names, vars(test.support))) + + try: from test.support import import_helper # type: ignore except ImportError: - import test.support - - names = 'modules_setup', 'modules_cleanup', 'DirsOnSysPath' - import_helper = types.SimpleNamespace(**Projection(names, vars(test.support))) + import_helper = from_test_support( + 'modules_setup', 'modules_cleanup', 'DirsOnSysPath' + ) try: from test.support import os_helper # type: ignore except ImportError: - - class os_helper: # type:ignore - from test.support import temp_dir + os_helper = from_test_support('temp_dir') try: