Skip to content

Commit cdbd58b

Browse files
serhiy-storchakajaraco
authored andcommitted
gh-119064: Use os_helper.FakePath instead of pathlib.Path in tests (python/cpython#119065)
Closes #116.
1 parent 18030dc commit cdbd58b

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ testing = [
4040
"more_itertools",
4141
"big-O",
4242
"pytest-ignore-flaky",
43+
"jaraco.test",
4344
]
4445
docs = [
4546
# upstream

‎tests/compat/__init__.py‎

Whitespace-only changes.

‎tests/compat/py39.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
3+
from jaraco.test.cpython import from_test_support, try_import
4+
5+
6+
os_helper = try_import('os_helper') or from_test_support(
7+
'FakePath',
8+
)
9+
10+
sys.modules[__name__ + '.os_helper'] = os_helper

‎tests/test_path.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import unittest
1010
import zipfile
1111

12+
from .compat.py39.os_helper import FakePath
13+
1214
import jaraco.itertools
1315
from jaraco.functools import compose
1416

@@ -269,13 +271,13 @@ def test_pathlike_construction(self, alpharep):
269271
zipp.Path should be constructable from a path-like object
270272
"""
271273
zipfile_ondisk = self.zipfile_ondisk(alpharep)
272-
pathlike = pathlib.Path(str(zipfile_ondisk))
274+
pathlike = FakePath(str(zipfile_ondisk))
273275
zipp.Path(pathlike)
274276

275277
@pass_alpharep
276278
def test_traverse_pathlike(self, alpharep):
277279
root = zipp.Path(alpharep)
278-
root / pathlib.Path("a")
280+
root / FakePath("a")
279281

280282
@pass_alpharep
281283
def test_parent(self, alpharep):
@@ -544,12 +546,12 @@ def test_inheritance(self, alpharep):
544546
['alpharep', 'path_type', 'subpath'],
545547
itertools.product(
546548
alpharep_generators,
547-
[str, pathlib.Path],
549+
[str, FakePath],
548550
['', 'b/'],
549551
),
550552
)
551553
def test_pickle(self, alpharep, path_type, subpath):
552-
zipfile_ondisk = path_type(self.zipfile_ondisk(alpharep))
554+
zipfile_ondisk = path_type(str(self.zipfile_ondisk(alpharep)))
553555

554556
saved_1 = pickle.dumps(zipp.Path(zipfile_ondisk, at=subpath))
555557
restored_1 = pickle.loads(saved_1)

0 commit comments

Comments
 (0)