"""Characterize album labeling (donor: album_label, fit_label; webapp.query.album_of mirrors album_label — asserted identical here).""" from pathlib import Path import photo_analyzer as pa from webapp import query def test_album_label_leaf_folder_relative(): lib = Path("/lib") assert pa.album_label(Path("/lib/Urlaub/Rom/a.jpg"), lib) == "Urlaub/Rom" assert pa.album_label(Path("/lib/Urlaub/Venedig/a.jpg"), lib) == "Urlaub/Venedig" assert pa.album_label(Path("/lib/a.jpg"), lib) == "(root)" assert pa.album_label(Path("/elsewhere/x/a.jpg"), lib) == "x", \ "outside library → bare parent name" assert pa.album_label(Path("/lib/x/a.jpg"), None) == "x" def test_webapp_album_of_mirrors_album_label(): lib = Path("/lib") for p in ("/lib/Urlaub/Rom/a.jpg", "/lib/a.jpg", "/other/x/a.jpg"): assert query.album_of(p, lib) == pa.album_label(Path(p), lib), p def test_albums_service_album_label_matches_donor(): # Parity: the extracted single implementation (US03-01) matches the donor rule # (donor_ledger.yaml: pa-album-label, wa-album-of). The service takes a tuple of # library roots; the donor takes one Path. from photo_pipeline.services.albums import album_label lib = Path("/lib") for p in ("/lib/Urlaub/Rom/a.jpg", "/lib/a.jpg", "/other/x/a.jpg", "/lib/x/y/a.jpg"): assert album_label(p, (lib,)) == pa.album_label(Path(p), lib), p # No configured roots → bare parent name, like the donor with library=None. assert album_label("/lib/x/a.jpg", ()) == pa.album_label(Path("/lib/x/a.jpg"), None) def test_fit_label_left_truncates(): assert pa.fit_label("short", 10) == "short" assert pa.fit_label("Urlaub/Somewhere/Rom", 8) == "…ere/Rom" assert len(pa.fit_label("Urlaub/Somewhere/Rom", 8)) == 8