Files
anonymisation/tests/unit/test_config_externalization.py
Domi31tls 380e520013 feat(gui): apply WIP profils+masques+build-windows from stash (2026-04-27)
Application du stash@{0} resté en WIP depuis le 27/04 :
  "On main: wip-gui-profils-masque-manuel-build-windows-2026-04-27"

## Apport

- Pseudonymisation_Gui_V5.py (+1208 lignes) : profils, panneau paramètres
  avancés, éditeur de masques intégré, gestion whitelist/blacklist
- launcher.py (+315) : splash natif PyInstaller, single-instance,
  téléchargement modèles
- anonymisation_onefile.spec : config PyInstaller mise à jour
- pdf_mask_designer.py (+114) : éditeur de masques amélioré
- config_defaults.py (+23) : constantes nouvelles
- tests/unit/test_config_externalization.py (+12) : tests config
- .gitignore (+5)

## Pourquoi

La version courante de la GUI sur la branche feature manquait :
- L'éditeur de masques
- Les profils
- Le panneau paramètres avancés
- Le splash natif au démarrage

Aucun conflit avec mes 10 commits Q-1 (pas de chevauchement de fichiers).

## Validation

75 passed, 10 xfailed sur pytest tests/unit/.

## Note

Le stash reste disponible dans `git stash list` jusqu'à drop explicite.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-02 11:09:46 +02:00

105 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""
Tests de non-régression pour la config externalisée.
"""
from pathlib import Path
import anonymizer_core_refactored_onnx as core
from config_defaults import (
deep_merge_dict,
ensure_runtime_dictionaries_config,
load_effective_dictionaries_dict,
load_effective_param_lists,
read_default_dictionaries_text,
read_runtime_dictionaries_overlay_text,
)
def test_default_config_template_is_externalized():
text = read_default_dictionaries_text()
assert "blacklist:" in text
assert "whitelist_phrases:" in text
cfg = core.load_dictionaries(None)
assert "CHCB" in cfg["blacklist"]["force_mask_terms"]
def test_runtime_overlay_template_is_minimal():
text = read_runtime_dictionaries_overlay_text()
assert "dictionnaires.default.yml" in text
assert "{}" in text
def test_deep_merge_dict_preserves_nested_defaults():
base = {
"whitelist": {
"sections_titres": ["DIM"],
"org_gpe_keep": False,
},
"flags": {
"case_insensitive": True,
"regex_engine": "python",
},
}
override = {
"whitelist": {
"sections_titres": ["GHM"],
"org_gpe_keep": True,
},
"flags": {
"regex_engine": "re2",
},
}
merged = deep_merge_dict(base, override)
assert merged["whitelist"]["sections_titres"] == ["DIM", "GHM"]
assert merged["whitelist"]["org_gpe_keep"] is True
assert merged["flags"]["case_insensitive"] is True
assert merged["flags"]["regex_engine"] == "re2"
def test_additional_stopwords_refresh_and_reset(tmp_path: Path):
cfg_path = tmp_path / "cfg.yml"
cfg_path.write_text("additional_stopwords:\n - xyzzymed\n", encoding="utf-8")
core.load_dictionaries(cfg_path)
assert "xyzzymed" in core._MEDICAL_STOP_WORDS_SET
assert "xyzzymed" in core._MEDICAL_STOP_WORDS
core.load_dictionaries(None)
assert "xyzzymed" not in core._MEDICAL_STOP_WORDS_SET
assert "xyzzymed" not in core._MEDICAL_STOP_WORDS
def test_runtime_overlay_is_created_and_effective_merge_works(tmp_path: Path):
cfg_path = tmp_path / "dictionnaires.yml"
created = ensure_runtime_dictionaries_config(cfg_path)
assert created == cfg_path
assert cfg_path.exists()
effective = load_effective_dictionaries_dict(cfg_path)
assert "CHCB" in effective["blacklist"]["force_mask_terms"]
cfg_path.write_text(
"blacklist:\n force_mask_terms:\n - LOCAL_SIGLE\n",
encoding="utf-8",
)
effective = load_effective_dictionaries_dict(cfg_path)
assert "CHCB" in effective["blacklist"]["force_mask_terms"]
assert "LOCAL_SIGLE" in effective["blacklist"]["force_mask_terms"]
def test_effective_param_lists_include_defaults_when_overlay_is_empty(tmp_path: Path):
cfg_path = tmp_path / "dictionnaires.yml"
cfg_path.write_text("{}\n", encoding="utf-8")
params = load_effective_param_lists(cfg_path)
assert "classification internationale" in params["whitelist_phrases"]
assert "CHCB" in params["blacklist_force_mask_terms"]
assert params["additional_stopwords"] == []