Skip to content

Commit

Permalink
Merge pull request #8 from jaraco/bugfix/parent-dir
Browse files Browse the repository at this point in the history
Return the parent of a directory properly
  • Loading branch information
jaraco committed Jul 7, 2019
2 parents 4715556 + 3bb3f6a commit 26bfd79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v0.5.2
======

#7: Parent of a directory now actually returns the parent.

v0.5.1
======

Expand Down
11 changes: 11 additions & 0 deletions test_zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,14 @@ def test_parent(self):
root = zipp.Path(zipfile_abcde)
assert (root / 'a').parent.at == ''
assert (root / 'a' / 'b').parent.at == 'a/'

def test_dir_parent(self):
for zipfile_abcde in self.zipfile_abcde():
root = zipp.Path(zipfile_abcde)
assert (root / 'b').parent.at == ''
assert (root / 'b/').parent.at == ''

def test_missing_dir_parent(self):
for zipfile_abcde in self.zipfile_abcde():
root = zipp.Path(zipfile_abcde)
assert (root / 'missing dir/').parent.at == ''
2 changes: 1 addition & 1 deletion zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _add_implied_dirs(names):

@property
def parent(self):
parent_at = posixpath.dirname(self.at)
parent_at = posixpath.dirname(self.at.rstrip('/'))
if parent_at:
parent_at += '/'
return self._next(parent_at)
Expand Down

0 comments on commit 26bfd79

Please sign in to comment.