Chore: Add a guard test so duplicate sample files cannot come back

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Trenton HandClaude Sonnet 5.5 committed 2026-10-03 15:41:49 -07:00
1 parent 5d5e85c159
commit 4ffe71c568
1 file changed
+25
+25
View File
@@ -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