Skip to content

Commit

Permalink
gh-119064: Use os_helper.FakePath instead of pathlib.Path in tests (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored and jaraco committed May 16, 2024
1 parent 18030dc commit cdbd58b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ testing = [
"more_itertools",
"big-O",
"pytest-ignore-flaky",
"jaraco.test",
]
docs = [
# upstream
Expand Down
Empty file added tests/compat/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/compat/py39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sys

from jaraco.test.cpython import from_test_support, try_import


os_helper = try_import('os_helper') or from_test_support(
'FakePath',
)

sys.modules[__name__ + '.os_helper'] = os_helper
10 changes: 6 additions & 4 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import unittest
import zipfile

from .compat.py39.os_helper import FakePath

import jaraco.itertools
from jaraco.functools import compose

Expand Down Expand Up @@ -269,13 +271,13 @@ def test_pathlike_construction(self, alpharep):
zipp.Path should be constructable from a path-like object
"""
zipfile_ondisk = self.zipfile_ondisk(alpharep)
pathlike = pathlib.Path(str(zipfile_ondisk))
pathlike = FakePath(str(zipfile_ondisk))
zipp.Path(pathlike)

@pass_alpharep
def test_traverse_pathlike(self, alpharep):
root = zipp.Path(alpharep)
root / pathlib.Path("a")
root / FakePath("a")

@pass_alpharep
def test_parent(self, alpharep):
Expand Down Expand Up @@ -544,12 +546,12 @@ def test_inheritance(self, alpharep):
['alpharep', 'path_type', 'subpath'],
itertools.product(
alpharep_generators,
[str, pathlib.Path],
[str, FakePath],
['', 'b/'],
),
)
def test_pickle(self, alpharep, path_type, subpath):
zipfile_ondisk = path_type(self.zipfile_ondisk(alpharep))
zipfile_ondisk = path_type(str(self.zipfile_ondisk(alpharep)))

saved_1 = pickle.dumps(zipp.Path(zipfile_ondisk, at=subpath))
restored_1 = pickle.loads(saved_1)
Expand Down

0 comments on commit cdbd58b

Please sign in to comment.