diff options
author | Barney Gale <barney.gale@gmail.com> | 2025-03-21 22:18:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-21 22:18:20 (GMT) |
commit | cf9d1a4b6b28a76a49edba4028d5533195172287 (patch) | |
tree | c20da37c6f435fe18a84b59ca83cbb3fae81c91f /Lib/test/test_pathlib/test_join.py | |
parent | 56d0f9af147b2280ea0af7af5e57df1a01271991 (diff) | |
download | cpython-cf9d1a4b6b28a76a49edba4028d5533195172287.zip cpython-cf9d1a4b6b28a76a49edba4028d5533195172287.tar.gz cpython-cf9d1a4b6b28a76a49edba4028d5533195172287.tar.bz2 |
GH-128520: pathlib ABCs: allow tests to be run externally (#131315)
Adjust the tests for the `pathlib.types` module so that they can be run
against the `pathlib-abc` PyPI package, which is a backport of the module
for older Python versions.
Specifically, we add a `.support.is_pypi` switch that is false in the
stdlib and true in the pathlib-abc package. This controls which package
we import, and whether or not we run tests against `PurePath` and `Path`.
For compatibility with older Python versions, we stop using
`zipfile.ZipFile.mkdir()` and `zipfile.ZipInfo._for_archive()`.
Diffstat (limited to 'Lib/test/test_pathlib/test_join.py')
-rw-r--r-- | Lib/test/test_pathlib/test_join.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/test/test_pathlib/test_join.py b/Lib/test/test_pathlib/test_join.py index 03a3ecf..f1a2420 100644 --- a/Lib/test/test_pathlib/test_join.py +++ b/Lib/test/test_pathlib/test_join.py @@ -4,9 +4,13 @@ Tests for pathlib.types._JoinablePath import unittest -from pathlib import PurePath, Path -from pathlib.types import _PathParser, _JoinablePath -from test.test_pathlib.support.lexical_path import LexicalPath +from .support import is_pypi +from .support.lexical_path import LexicalPath + +if is_pypi: + from pathlib_abc import _PathParser, _JoinablePath +else: + from pathlib.types import _PathParser, _JoinablePath class JoinTestBase: @@ -355,12 +359,14 @@ class LexicalPathJoinTest(JoinTestBase, unittest.TestCase): cls = LexicalPath -class PurePathJoinTest(JoinTestBase, unittest.TestCase): - cls = PurePath +if not is_pypi: + from pathlib import PurePath, Path + class PurePathJoinTest(JoinTestBase, unittest.TestCase): + cls = PurePath -class PathJoinTest(JoinTestBase, unittest.TestCase): - cls = Path + class PathJoinTest(JoinTestBase, unittest.TestCase): + cls = Path if __name__ == "__main__": |