Skip to content

Commit

Permalink
Use PurePosixPath for relative paths within a zip file. Fixes failing…
Browse files Browse the repository at this point in the history
… test on Windows. Added test for relative paths with subdirectories.
  • Loading branch information
jaraco committed Nov 25, 2022
1 parent 4e271ca commit 057ed57
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion tests/test_zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ def test_is_symlink(self, alpharep):
def test_relative_to(self, alpharep):
root = zipp.Path(alpharep)
relative = root.joinpath("b", "c.txt").relative_to(root / "b")
assert relative == pathlib.Path("c.txt")
assert relative == pathlib.PurePosixPath("c.txt")

relative = root.joinpath("b", "d", "e.txt").relative_to(root / "b")
assert str(relative) == "d/e.txt"

@pass_alpharep
def test_inheritance(self, alpharep):
Expand Down
4 changes: 2 additions & 2 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ def rglob(self, pattern):
return self.glob(f'**/{pattern}')

def relative_to(self, *other, **kwargs):
other = (pathlib.Path(each.at) for each in other)
return pathlib.Path(self.at).relative_to(*other, **kwargs)
other = (pathlib.PurePosixPath(each.at) for each in other)
return pathlib.PurePosixPath(self.at).relative_to(*other, **kwargs)

def __str__(self):
return posixpath.join(self.root.filename, self.at)
Expand Down

0 comments on commit 057ed57

Please sign in to comment.