Repository: jaraco/zipp

Issue:
Attempting to get a parent of a dir results in the same object
In ae4be5a, I illustrate an issue I discovered where retrieving the parent of a directory results in the same object and not actually the parent.

Discussion:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 7cb2095..4a64ccf 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,8 @@
+v0.5.2
+======
+
+#7: Parent of a directory now actually returns the parent.
+
 v0.5.1
 ======
 
diff --git a/appveyor.yml b/appveyor.yml
index f35aa27..2b7808f 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -18,7 +18,7 @@ cache:
   - '%LOCALAPPDATA%\pip\Cache'
 
 test_script:
-  - "python -m pip install -U tox tox-venv virtualenv"
+  - "python -m pip install tox tox-venv"
   - "tox"
 
 version: '{build}'
diff --git a/tox.ini b/tox.ini
index 175afb2..02e18c9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -24,7 +24,8 @@ commands =
 skip_install = True
 deps =
 	pep517>=0.5
-	twine>=1.13
+	# workaround for https://github.com/pypa/twine/issues/423
+	git+https://github.com/pypa/twine
 	path.py
 commands =
 	python -c "import path; path.Path('dist').rmtree_p()"
diff --git a/zipp.py b/zipp.py
index 918e688..8cdfdc0 100644
--- a/zipp.py
+++ b/zipp.py
@@ -159,7 +159,7 @@ class Path:
 
     @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)


Test patch:
diff --git a/test_zipp.py b/test_zipp.py
index da68fea..e084374 100644
--- a/test_zipp.py
+++ b/test_zipp.py
@@ -170,3 +170,14 @@ class TestEverything(unittest.TestCase):
             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 == ''