diff --git a/tests/test_importer_archive.py b/tests/test_importer_archive.py index 3b72057..713678b 100644 --- a/tests/test_importer_archive.py +++ b/tests/test_importer_archive.py @@ -48,13 +48,31 @@ def _jpeg_bytes(color): return buf.getvalue() +def _split_bytes(orient): + """Structured half/half image — solid colors phash-collapse (distance + 0); orthogonal splits are distinct only at phash_threshold=0 (see + reference-phash-test-images).""" + im = Image.new("L", (256, 256), 0) + px = im.load() + for y in range(256): + for x in range(256): + if (x / 256 if orient == "v" else y / 256) >= 0.5: + px[x, y] = 255 + buf = io.BytesIO() + im.convert("RGB").save(buf, "JPEG") + return buf.getvalue() + + def test_archive_imports_members_and_stores_archive(importer, import_layout): import_root, _ = import_layout + # Distinct structure + threshold 0 so BOTH members import (solid + # colors would phash-collapse; reference-phash-test-images). + importer.settings.phash_threshold = 0 arc = import_root / "Bob" / "set.cbz" arc.parent.mkdir(parents=True, exist_ok=True) with zipfile.ZipFile(arc, "w") as zf: - zf.writestr("a.jpg", _jpeg_bytes((200, 10, 10))) - zf.writestr("b.jpg", _jpeg_bytes((10, 200, 10))) + zf.writestr("a.jpg", _split_bytes("v")) + zf.writestr("b.jpg", _split_bytes("h")) zf.writestr("readme.txt", b"hello") arc.with_suffix(".cbz.json").write_text(json.dumps( {"category": "patreon", "id": "777", "title": "Set"})) diff --git a/tests/test_provenance_service.py b/tests/test_provenance_service.py index 5cdbf60..7cc2aed 100644 --- a/tests/test_provenance_service.py +++ b/tests/test_provenance_service.py @@ -58,7 +58,9 @@ async def test_for_image_no_provenance_returns_empty_list(db): rec = await _seed_image(db) svc = ProvenanceService(db) payload = await svc.for_image(rec.id) - assert payload == {"image_id": rec.id, "provenance": []} + assert payload == { + "image_id": rec.id, "provenance": [], "attachments": [] + } @pytest.mark.asyncio