mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
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()`.
This commit is contained in:
parent
56d0f9af14
commit
cf9d1a4b6b
10 changed files with 127 additions and 72 deletions
|
@ -6,12 +6,16 @@ import collections.abc
|
|||
import io
|
||||
import unittest
|
||||
|
||||
from pathlib import Path
|
||||
from pathlib.types import PathInfo, _ReadablePath
|
||||
from pathlib._os import magic_open
|
||||
from .support import is_pypi
|
||||
from .support.local_path import ReadableLocalPath, LocalPathGround
|
||||
from .support.zip_path import ReadableZipPath, ZipPathGround
|
||||
|
||||
from test.test_pathlib.support.local_path import ReadableLocalPath, LocalPathGround
|
||||
from test.test_pathlib.support.zip_path import ReadableZipPath, ZipPathGround
|
||||
if is_pypi:
|
||||
from pathlib_abc import PathInfo, _ReadablePath
|
||||
from pathlib_abc._os import magic_open
|
||||
else:
|
||||
from pathlib.types import PathInfo, _ReadablePath
|
||||
from pathlib._os import magic_open
|
||||
|
||||
|
||||
class ReadTestBase:
|
||||
|
@ -301,8 +305,11 @@ class LocalPathReadTest(ReadTestBase, unittest.TestCase):
|
|||
ground = LocalPathGround(ReadableLocalPath)
|
||||
|
||||
|
||||
class PathReadTest(ReadTestBase, unittest.TestCase):
|
||||
ground = LocalPathGround(Path)
|
||||
if not is_pypi:
|
||||
from pathlib import Path
|
||||
|
||||
class PathReadTest(ReadTestBase, unittest.TestCase):
|
||||
ground = LocalPathGround(Path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue