raise error if passed base is not a zipfile or dir

This commit is contained in:
Sean Breckenridge 2021-07-01 06:55:41 -07:00
parent e065145162
commit f076263993
2 changed files with 15 additions and 1 deletions

View file

@ -118,6 +118,10 @@ def match_structure(
zf = zipfile.ZipFile(base)
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] = []
possible_targets: List[Path] = [searchdir]

View file

@ -1,7 +1,10 @@
from my.core.structure import match_structure
import pytest
from pathlib import Path
from my.core.structure import match_structure
structure_data: Path = Path(__file__).parent / "structure_data"
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
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