raise error if passed base is not a zipfile or dir
This commit is contained in:
parent
e065145162
commit
f076263993
2 changed files with 15 additions and 1 deletions
|
@ -118,6 +118,10 @@ def match_structure(
|
||||||
zf = zipfile.ZipFile(base)
|
zf = zipfile.ZipFile(base)
|
||||||
zf.extractall(path=sd)
|
zf.extractall(path=sd)
|
||||||
|
|
||||||
|
else:
|
||||||
|
if not searchdir.is_dir():
|
||||||
|
raise NotADirectoryError(f"Expected either a zipfile or a directory, received {searchdir}")
|
||||||
|
|
||||||
matches: List[Path] = []
|
matches: List[Path] = []
|
||||||
possible_targets: List[Path] = [searchdir]
|
possible_targets: List[Path] = [searchdir]
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
from my.core.structure import match_structure
|
import pytest
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from my.core.structure import match_structure
|
||||||
|
|
||||||
|
|
||||||
structure_data: Path = Path(__file__).parent / "structure_data"
|
structure_data: Path = Path(__file__).parent / "structure_data"
|
||||||
|
|
||||||
gdpr_expected = ("comments", "messages/index.csv", "profile")
|
gdpr_expected = ("comments", "messages/index.csv", "profile")
|
||||||
|
@ -25,3 +28,10 @@ def test_gdpr_unzip() -> None:
|
||||||
# make sure the temporary directory this created no longer exists
|
# make sure the temporary directory this created no longer exists
|
||||||
assert not extracted.exists()
|
assert not extracted.exists()
|
||||||
|
|
||||||
|
|
||||||
|
def test_not_directory() -> None:
|
||||||
|
with pytest.raises(NotADirectoryError, match=r"Expected either a zipfile or a directory"):
|
||||||
|
with match_structure(
|
||||||
|
structure_data / "messages/index.csv", expected=gdpr_expected
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue