Skip to content

Commit

Permalink
Extract method for resolving the 'base' for name/suffix/suffixes/stem…
Browse files Browse the repository at this point in the history
… operations

Fixes #96
  • Loading branch information
jaraco committed Jul 14, 2023
1 parent c208e98 commit c230378
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions newsfragments/96.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed name/suffix/suffixes/stem operations when no filename is present and the Path is not at the root of the zipfile.
3 changes: 0 additions & 3 deletions tests/test_zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,6 @@ def test_suffixes(self, alpharep):
e = root / '.hgrc'
assert e.suffixes == []

import pytest

@pytest.mark.xfail(reason="96")
@pass_alpharep
def test_suffix_no_filename(self, alpharep):
alpharep.filename = None
Expand Down
11 changes: 7 additions & 4 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,21 +298,24 @@ def open(self, mode='r', *args, pwd=None, **kwargs):
encoding, args, kwargs = _extract_text_encoding(*args, **kwargs)
return io.TextIOWrapper(stream, encoding, *args, **kwargs)

def _base(self):
return pathlib.Path(self.at) if self.at else self.filename

@property
def name(self):
return pathlib.Path(self.at).name or self.filename.name
return self._base().name

@property
def suffix(self):
return pathlib.Path(self.at).suffix or self.filename.suffix
return self._base().suffix

@property
def suffixes(self):
return pathlib.Path(self.at).suffixes or self.filename.suffixes
return self._base().suffixes

@property
def stem(self):
return pathlib.Path(self.at).stem or self.filename.stem
return self._base().stem

@property
def filename(self):
Expand Down

0 comments on commit c230378

Please sign in to comment.