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:
Barney Gale 2025-03-21 22:18:20 +00:00 committed by GitHub
parent 56d0f9af14
commit cf9d1a4b6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 127 additions and 72 deletions

View file

@ -4,11 +4,17 @@
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