diff options
author | Barney Gale <barney.gale@gmail.com> | 2025-03-21 22:18:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-21 22:18:20 +0000 |
commit | cf9d1a4b6b28a76a49edba4028d5533195172287 (patch) | |
tree | c20da37c6f435fe18a84b59ca83cbb3fae81c91f /Lib/test/test_pathlib/test_copy.py | |
parent | 56d0f9af147b2280ea0af7af5e57df1a01271991 (diff) | |
download | cpython-cf9d1a4b6b28a76a49edba4028d5533195172287.tar.gz cpython-cf9d1a4b6b28a76a49edba4028d5533195172287.zip |
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_copy.py')
-rw-r--r-- | Lib/test/test_pathlib/test_copy.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/Lib/test/test_pathlib/test_copy.py b/Lib/test/test_pathlib/test_copy.py index 698a0a7b750..5f4cf82a031 100644 --- a/Lib/test/test_pathlib/test_copy.py +++ b/Lib/test/test_pathlib/test_copy.py @@ -5,10 +5,9 @@ Tests for copying from pathlib.types._ReadablePath to _WritablePath. import contextlib import unittest -from pathlib import Path - -from test.test_pathlib.support.local_path import LocalPathGround, WritableLocalPath -from test.test_pathlib.support.zip_path import ZipPathGround, ReadableZipPath, WritableZipPath +from .support import is_pypi +from .support.local_path import LocalPathGround +from .support.zip_path import ZipPathGround, ReadableZipPath, WritableZipPath class CopyTestBase: @@ -53,7 +52,7 @@ class CopyTestBase: self.target_ground.readbytes(result)) def test_copy_file_to_directory(self): - if not isinstance(self.target_root, WritableLocalPath): + if isinstance(self.target_root, WritableZipPath): self.skipTest('needs local target') source = self.source_root / 'fileA' target = self.target_root / 'copyA' @@ -113,7 +112,7 @@ class CopyTestBase: self.assertEqual(self.target_ground.readlink(target / 'linkD'), 'dirD') def test_copy_dir_to_existing_directory(self): - if not isinstance(self.target_root, WritableLocalPath): + if isinstance(self.target_root, WritableZipPath): self.skipTest('needs local target') source = self.source_root / 'dirC' target = self.target_root / 'copyC' @@ -153,19 +152,22 @@ class ZipToZipPathCopyTest(CopyTestBase, unittest.TestCase): target_ground = ZipPathGround(WritableZipPath) -class ZipToLocalPathCopyTest(CopyTestBase, unittest.TestCase): - source_ground = ZipPathGround(ReadableZipPath) - target_ground = LocalPathGround(Path) +if not is_pypi: + from pathlib import Path + class ZipToLocalPathCopyTest(CopyTestBase, unittest.TestCase): + source_ground = ZipPathGround(ReadableZipPath) + target_ground = LocalPathGround(Path) -class LocalToZipPathCopyTest(CopyTestBase, unittest.TestCase): - source_ground = LocalPathGround(Path) - target_ground = ZipPathGround(WritableZipPath) + + class LocalToZipPathCopyTest(CopyTestBase, unittest.TestCase): + source_ground = LocalPathGround(Path) + target_ground = ZipPathGround(WritableZipPath) -class LocalToLocalPathCopyTest(CopyTestBase, unittest.TestCase): - source_ground = LocalPathGround(Path) - target_ground = LocalPathGround(Path) + class LocalToLocalPathCopyTest(CopyTestBase, unittest.TestCase): + source_ground = LocalPathGround(Path) + target_ground = LocalPathGround(Path) if __name__ == "__main__": |