Files
anonymisation/tests/unit/test_gui_batch_paths.py
Domi31tls f2375d6be2 test: non-régression F5 + batch paths + masquage manuel + layouts réels
- test_f5_nom_compose_orphelin.py : 13 tests (regex F5, application, scénario Trackare EJNAINI)
- test_gui_batch_paths.py / test_manual_masking.py : couverture des modules
- test_real_world_identifier_layouts.py : non-régression layouts réels (D-15)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:30:56 +02:00

71 lines
2.3 KiB
Python

from pathlib import Path
from gui_batch_paths import (
build_batch_output_dir,
iter_pseudonymized_texts,
list_supported_documents,
)
def test_list_supported_documents_excludes_gui_output_tree(tmp_path: Path):
root = tmp_path / "cases"
source_case = root / "001_patient_header_and_birth"
source_case.mkdir(parents=True)
nested_case = root / "002_contact_bundle"
nested_case.mkdir(parents=True)
output_case = root / "anonymise" / "001_patient_header_and_birth"
output_case.mkdir(parents=True)
source_txt = source_case / "test.txt"
source_pdf = nested_case / "source.pdf"
output_txt = output_case / "test.pseudonymise.txt"
source_txt.write_text("source", encoding="utf-8")
source_pdf.write_text("pdf", encoding="utf-8")
output_txt.write_text("output", encoding="utf-8")
documents = list_supported_documents(root, {".txt", ".pdf"})
assert documents == [source_txt, source_pdf]
def test_build_batch_output_dir_preserves_relative_parent(tmp_path: Path):
root = tmp_path / "cases"
output_root = root / "anonymise"
source = root / "010_spaced_establishment_header" / "test.txt"
source.parent.mkdir(parents=True)
source.write_text("test", encoding="utf-8")
output_dir = build_batch_output_dir(root, output_root, source)
assert output_dir == output_root / "010_spaced_establishment_header"
def test_build_batch_output_dir_keeps_root_files_at_output_root(tmp_path: Path):
root = tmp_path / "cases"
output_root = root / "anonymise"
source = root / "test.txt"
root.mkdir(parents=True)
source.write_text("test", encoding="utf-8")
output_dir = build_batch_output_dir(root, output_root, source)
assert output_dir == output_root
def test_iter_pseudonymized_texts_is_recursive(tmp_path: Path):
output_root = tmp_path / "anonymise"
nested = output_root / "001_patient_header_and_birth"
nested.mkdir(parents=True)
top_level = output_root / "summary.pseudonymise.txt"
nested_txt = nested / "test.pseudonymise.txt"
other_file = nested / "audit.jsonl"
top_level.write_text("top", encoding="utf-8")
nested_txt.write_text("nested", encoding="utf-8")
other_file.write_text("{}", encoding="utf-8")
found = sorted(iter_pseudonymized_texts(output_root))
assert found == [nested_txt, top_level]