From cf9d1a4b6b28a76a49edba4028d5533195172287 Mon Sep 17 00:00:00 2001 From: Barney Gale Date: Fri, 21 Mar 2025 22:18:20 +0000 Subject: 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()`. --- Lib/test/test_pathlib/test_join_posix.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'Lib/test/test_pathlib/test_join_posix.py') diff --git a/Lib/test/test_pathlib/test_join_posix.py b/Lib/test/test_pathlib/test_join_posix.py index 7f657c2565d..d24fb1087c9 100644 --- a/Lib/test/test_pathlib/test_join_posix.py +++ b/Lib/test/test_pathlib/test_join_posix.py @@ -5,8 +5,8 @@ Tests for Posix-flavoured pathlib.types._JoinablePath import os import unittest -from pathlib import PurePosixPath, PosixPath -from test.test_pathlib.support.lexical_path import LexicalPosixPath +from .support import is_pypi +from .support.lexical_path import LexicalPosixPath class JoinTestBase: @@ -36,13 +36,15 @@ class LexicalPosixPathJoinTest(JoinTestBase, unittest.TestCase): cls = LexicalPosixPath -class PurePosixPathJoinTest(JoinTestBase, unittest.TestCase): - cls = PurePosixPath +if not is_pypi: + from pathlib import PurePosixPath, PosixPath + class PurePosixPathJoinTest(JoinTestBase, unittest.TestCase): + cls = PurePosixPath -if os.name != 'nt': - class PosixPathJoinTest(JoinTestBase, unittest.TestCase): - cls = PosixPath + if os.name != 'nt': + class PosixPathJoinTest(JoinTestBase, unittest.TestCase): + cls = PosixPath if __name__ == "__main__": -- cgit v1.2.3