summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/hircine/scraper/utils.py2
-rw-r--r--tests/scrapers/test_scraper_utils.py41
2 files changed, 41 insertions, 2 deletions
diff --git a/src/hircine/scraper/utils.py b/src/hircine/scraper/utils.py
index 61c7d14..5a383a2 100644
--- a/src/hircine/scraper/utils.py
+++ b/src/hircine/scraper/utils.py
@@ -35,7 +35,7 @@ def parse_dict(parsers, data):
@contextmanager
-def open_archive_file(archive, member, check_sidecar=True): # pragma: no cover
+def open_archive_file(archive, member, check_sidecar=True):
"""
Open an archive file for use with the :ref:`with <with>` statement. Yields
a :term:`file object` obtained from:
diff --git a/tests/scrapers/test_scraper_utils.py b/tests/scrapers/test_scraper_utils.py
index 193cf2a..4b02aad 100644
--- a/tests/scrapers/test_scraper_utils.py
+++ b/tests/scrapers/test_scraper_utils.py
@@ -1,4 +1,10 @@
-from hircine.scraper.utils import parse_dict
+import json
+import os
+from zipfile import ZipFile
+
+import pytest
+
+from hircine.scraper.utils import open_archive_file, parse_dict
def test_parse_dict():
@@ -26,3 +32,36 @@ def test_parse_dict():
"list_plugh",
"list_xyzzy",
]
+
+
+@pytest.mark.parametrize(
+ "check_sidecar",
+ [
+ (False),
+ (True),
+ ],
+ ids=[
+ "zip",
+ "sidecar",
+ ],
+)
+def test_open_archive_file(gen_archive, tmpdir, check_sidecar):
+ archive = next(gen_archive)
+ archive.path = os.path.join(tmpdir, "archive.zip")
+
+ zip_data = {"zip": "data"}
+ sidecar_data = {"sidecar": "data"}
+
+ with open(f"{archive.path}.info.json", "x") as handle:
+ json.dump(sidecar_data, handle)
+
+ with ZipFile(archive.path, "x") as ziph:
+ ziph.writestr("info.json", json.dumps(zip_data))
+
+ with open_archive_file(archive, "info.json", check_sidecar=check_sidecar) as file:
+ data = json.load(file)
+
+ if check_sidecar:
+ assert data == sidecar_data
+ else:
+ assert data == zip_data