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
|
@ -5,8 +5,8 @@ Tests for Windows-flavoured pathlib.types._JoinablePath
|
|||
import os
|
||||
import unittest
|
||||
|
||||
from pathlib import PureWindowsPath, WindowsPath
|
||||
from test.test_pathlib.support.lexical_path import LexicalWindowsPath
|
||||
from .support import is_pypi
|
||||
from .support.lexical_path import LexicalWindowsPath
|
||||
|
||||
|
||||
class JoinTestBase:
|
||||
|
@ -40,8 +40,6 @@ class JoinTestBase:
|
|||
pp = p.joinpath('E:d:s')
|
||||
self.assertEqual(pp, P('E:d:s'))
|
||||
# Joining onto a UNC path with no root
|
||||
pp = P('//').joinpath('server')
|
||||
self.assertEqual(pp, P('//server'))
|
||||
pp = P('//server').joinpath('share')
|
||||
self.assertEqual(pp, P(r'//server\share'))
|
||||
pp = P('//./BootPartition').joinpath('Windows')
|
||||
|
@ -54,7 +52,7 @@ class JoinTestBase:
|
|||
self.assertEqual(p / 'x/y', P(r'C:/a/b\x/y'))
|
||||
self.assertEqual(p / 'x' / 'y', P(r'C:/a/b\x\y'))
|
||||
self.assertEqual(p / '/x/y', P('C:/x/y'))
|
||||
self.assertEqual(p / '/x' / 'y', P('C:/x\y'))
|
||||
self.assertEqual(p / '/x' / 'y', P(r'C:/x\y'))
|
||||
# Joining with a different drive => the first path is ignored, even
|
||||
# if the second path is relative.
|
||||
self.assertEqual(p / 'D:x/y', P('D:x/y'))
|
||||
|
@ -277,13 +275,15 @@ class LexicalWindowsPathJoinTest(JoinTestBase, unittest.TestCase):
|
|||
cls = LexicalWindowsPath
|
||||
|
||||
|
||||
class PureWindowsPathJoinTest(JoinTestBase, unittest.TestCase):
|
||||
cls = PureWindowsPath
|
||||
if not is_pypi:
|
||||
from pathlib import PureWindowsPath, WindowsPath
|
||||
|
||||
class PureWindowsPathJoinTest(JoinTestBase, unittest.TestCase):
|
||||
cls = PureWindowsPath
|
||||
|
||||
if os.name == 'nt':
|
||||
class WindowsPathJoinTest(JoinTestBase, unittest.TestCase):
|
||||
cls = WindowsPath
|
||||
if os.name == 'nt':
|
||||
class WindowsPathJoinTest(JoinTestBase, unittest.TestCase):
|
||||
cls = WindowsPath
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue