ZipPath: support hash, iterdir and proper / operator

This commit is contained in:
Dima Gerasimov 2022-04-15 13:34:09 +01:00 committed by karlicoss
parent e6e948de9c
commit 599a8b0dd7
2 changed files with 35 additions and 10 deletions

View file

@ -63,12 +63,17 @@ def test_zippath() -> None:
# magic! convenient to make third party libraries agnostic of ZipPath
assert isinstance(zp, Path)
assert isinstance(zp, ZipPath)
assert isinstance(zp / 'subpath', Path)
# TODO maybe change __str__/__repr__? since it's a bit misleading:
# Path('/code/hpi/tests/core/structure_data/gdpr_export.zip', 'gdpr_export/')
assert ZipPath(target) == ZipPath(target)
assert zp.absolute() == zp
# shouldn't crash
hash(zp)
assert zp.exists()
assert (zp / 'gdpr_export/comments').exists()
# check str constructor just in case
@ -77,7 +82,7 @@ def test_zippath() -> None:
matched = list(zp.rglob('*'))
assert len(matched) > 0
assert all(p.filename == str(target) for p in matched), matched
assert all(p.filepath == target for p in matched), matched
rpaths = [str(p.relative_to(zp)) for p in matched]
assert rpaths == [
@ -106,3 +111,7 @@ def test_zippath() -> None:
]
assert list(zp.rglob('mes*')) == [ZipPath(target, 'gdpr_export/messages')]
iterdir_res = list((zp / 'gdpr_export').iterdir())
assert len(iterdir_res) == 3
assert all(isinstance(p, Path) for p in iterdir_res)