diff --git a/src/documents/tests/test_sample_files.py b/src/documents/tests/test_sample_files.py index 44919da30..04d088d80 100644 --- a/src/documents/tests/test_sample_files.py +++ b/src/documents/tests/test_sample_files.py @@ -1,6 +1,8 @@ import hashlib +from collections import defaultdict from pathlib import Path +from paperless_testing.samples import SHARED_SAMPLES_DIR from paperless_testing.samples import SIMPLE_DIGITAL_PDF from paperless_testing.samples import install_document_samples @@ -32,3 +34,26 @@ def test_install_recreates_every_historical_opaque_name(tmp_path: Path) -> None: def test_install_uses_the_shared_bytes(tmp_path: Path) -> None: install_document_samples(tmp_path) assert _sha(tmp_path / "originals" / "0000001.pdf") == _sha(SIMPLE_DIGITAL_PDF) + + +APP_SAMPLE_TREES = [ + Path(__file__).parent / "samples", + Path(__file__).parents[2] / "paperless" / "tests" / "samples", + Path(__file__).parent / "examples", + SHARED_SAMPLES_DIR, +] + + +def test_no_two_sample_files_have_identical_bytes() -> None: + by_hash: dict[str, list[Path]] = defaultdict(list) + for tree in APP_SAMPLE_TREES: + for path in tree.rglob("*"): + if path.is_file(): + by_hash[_sha(path)].append(path) + duplicates = {h: ps for h, ps in by_hash.items() if len(ps) > 1} + lines = [" " + ", ".join(str(p) for p in ps) for ps in duplicates.values()] + message = ( + "Duplicate sample files, move one to paperless_testing/sample_files:\n" + + "\n".join(lines) + ) + assert not duplicates, message