bpo-37520: Correct behavior for zipfile.Path.parent (GH-14638) (GH-14641)
* bpo-37520: Correct behavior for zipfile.Path.parent
* 📜🤖 Added by blurb_it.
(cherry picked from commit 38f44b4a4a
)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
This commit is contained in:
parent
3f7d0c9665
commit
66905d1467
|
@ -2514,5 +2514,16 @@ class TestPath(unittest.TestCase):
|
||||||
assert (root / 'a').parent.at == ''
|
assert (root / 'a').parent.at == ''
|
||||||
assert (root / 'a' / 'b').parent.at == 'a/'
|
assert (root / 'a' / 'b').parent.at == 'a/'
|
||||||
|
|
||||||
|
def test_dir_parent(self):
|
||||||
|
for zipfile_abcde in self.zipfile_abcde():
|
||||||
|
root = zipfile.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 = zipfile.Path(zipfile_abcde)
|
||||||
|
assert (root / 'missing dir/').parent.at == ''
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -2236,7 +2236,7 @@ class Path:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
parent_at = posixpath.dirname(self.at)
|
parent_at = posixpath.dirname(self.at.rstrip('/'))
|
||||||
if parent_at:
|
if parent_at:
|
||||||
parent_at += '/'
|
parent_at += '/'
|
||||||
return self._next(parent_at)
|
return self._next(parent_at)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Correct behavior for zipfile.Path.parent when the path object identifies a subdirectory.
|
Loading…
Reference in New Issue