summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib/support/lexical_path.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2025-03-21 22:18:20 (GMT)
committerGitHub <noreply@github.com>2025-03-21 22:18:20 (GMT)
commitcf9d1a4b6b28a76a49edba4028d5533195172287 (patch)
treec20da37c6f435fe18a84b59ca83cbb3fae81c91f /Lib/test/test_pathlib/support/lexical_path.py
parent56d0f9af147b2280ea0af7af5e57df1a01271991 (diff)
downloadcpython-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/support/lexical_path.py')
-rw-r--r--Lib/test/test_pathlib/support/lexical_path.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/test/test_pathlib/support/lexical_path.py b/Lib/test/test_pathlib/support/lexical_path.py
index 6298513..f29a521 100644
--- a/Lib/test/test_pathlib/support/lexical_path.py
+++ b/Lib/test/test_pathlib/support/lexical_path.py
@@ -4,11 +4,17 @@ Simple implementation of JoinablePath, for use in pathlib tests.
import ntpath
import os.path
-import pathlib.types
import posixpath
+from . import is_pypi
-class LexicalPath(pathlib.types._JoinablePath):
+if is_pypi:
+ from pathlib_abc import _JoinablePath
+else:
+ from pathlib.types import _JoinablePath
+
+
+class LexicalPath(_JoinablePath):
__slots__ = ('_segments',)
parser = os.path