From 3531507c7a275cfcbdefe02e0aed4f92ff589b09 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 05:11:25 -0400 Subject: [PATCH] Fix test failures on older Pythons with os_helper shim. Copied 'from_test_support' from importlib_resources. --- setup.cfg | 1 + tests/fixtures.py | 6 ++++-- tests/py39compat.py | 18 ++++++++++++++++-- tests/test_main.py | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 71b66b39..f67df574 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,6 +37,7 @@ testing = pyfakefs flufl.flake8 pytest-perf >= 0.9.2 + jaraco.collections docs = # upstream diff --git a/tests/fixtures.py b/tests/fixtures.py index 7daae16a..88478050 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -9,7 +9,7 @@ import functools import contextlib -from .py39compat import FS_NONASCII +from .py39compat import os_helper from . import _path from ._path import FilesSpec @@ -335,7 +335,9 @@ def record_names(file_defs): class FileBuilder: def unicode_filename(self): - return FS_NONASCII or self.skip("File system does not support non-ascii.") + return os_helper.FS_NONASCII or self.skip( + "File system does not support non-ascii." + ) def DALS(str): diff --git a/tests/py39compat.py b/tests/py39compat.py index 926dcad9..b01ecad8 100644 --- a/tests/py39compat.py +++ b/tests/py39compat.py @@ -1,4 +1,18 @@ +import types + +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.os_helper import FS_NONASCII + from test.support import os_helper # type: ignore except ImportError: - from test.support import FS_NONASCII # noqa + os_helper = from_test_support('FS_NONASCII', 'skip_unless_symlink') diff --git a/tests/test_main.py b/tests/test_main.py index 45d74534..c94ab0f4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -5,7 +5,7 @@ import importlib import importlib_metadata import contextlib -from test.support import os_helper +from .py39compat import os_helper import pyfakefs.fake_filesystem_unittest as ffs