Le module usage_telemetry est maintenant réellement branché : la GUI V6 envoie les statistiques au portail après chaque run (les stats web restaient vides sans cela). - processing_runner : RunSummary porte une liste DocResult (ordinal, page_count via page_count_for, status, duration_ms, extension) — peuplée dans la boucle. Aucun nom/chemin de fichier. - usage_telemetry : report_run_summary(summary, base_url, license_ref, machine_id, session, ...) construit le payload depuis le RunSummary et l'envoie (non bloquant). N'envoie RIEN sans license_ref. Spool JSONL si échec réseau. - tab_usage : _finish() déclenche l'envoi en thread daemon (jamais bloquant pour l'UI ni le run). - app : fournit le reporter à UsageTab avec le contexte licence (base_url du LicenseClient, license_ref via local_status, machine_id, app_version). Tests : RunSummary.documents peuplé (0 chemin) ; report_run_summary (payload correct, réseau KO → spool sans crash, pas d'envoi sans licence) ; _finish appelle le reporter. 252 tests unit OK (0 régression), self-test OK. V5/moteur/app_aivanov intacts, 0 dépendance. Aucun build/push sans GO Dom. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
190 lines
5.9 KiB
Python
190 lines
5.9 KiB
Python
"""Vue lisible d'un profil d'anonymisation (logique pure, sans display).
|
|
|
|
Sous-tend le sous-onglet « Profils » et la fenêtre « Tableau des termes ».
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from gui_v6.profile_view import (
|
|
filter_term_rows,
|
|
profile_term_rows,
|
|
summarize_profile,
|
|
)
|
|
|
|
_PROFILE = {
|
|
"label": "Standard local",
|
|
"description": "Profil par défaut.",
|
|
"require_manual_mask": True,
|
|
"force_disable_vlm": True,
|
|
"preferred_manual_mask_template": "config/mask_templates/x.json",
|
|
"param_lists": {
|
|
"whitelist_phrases": ["classification internationale", "prise en charge"],
|
|
"blacklist_force_mask_terms": ["CHUXX"],
|
|
"additional_stopwords": [],
|
|
},
|
|
}
|
|
|
|
|
|
def test_summarize_profile_reads_real_fields():
|
|
s = summarize_profile("standard_local", _PROFILE)
|
|
assert s.key == "standard_local"
|
|
assert s.label == "Standard local"
|
|
assert s.description == "Profil par défaut."
|
|
assert s.require_manual_mask is True
|
|
assert s.disable_vlm is True
|
|
assert s.mask_template == "config/mask_templates/x.json"
|
|
assert s.list_counts == {"À conserver": 2, "À masquer": 1, "À ignorer": 0}
|
|
|
|
|
|
def test_summarize_profile_tolerates_empty():
|
|
s = summarize_profile("vide", {})
|
|
assert s.label == "vide"
|
|
assert s.description == ""
|
|
assert s.require_manual_mask is False
|
|
assert s.mask_template == ""
|
|
assert s.list_counts == {"À conserver": 0, "À masquer": 0, "À ignorer": 0}
|
|
|
|
s2 = summarize_profile("none", None)
|
|
assert s2.list_counts["À masquer"] == 0
|
|
|
|
|
|
def test_profile_term_rows_type_term_source():
|
|
rows = profile_term_rows(_PROFILE)
|
|
assert ("À conserver", "classification internationale", "Standard local") in rows
|
|
assert ("À masquer", "CHUXX", "Standard local") in rows
|
|
# 2 whitelist + 1 blacklist + 0 stopwords
|
|
assert len(rows) == 3
|
|
|
|
|
|
def test_filter_term_rows_by_query():
|
|
rows = profile_term_rows(_PROFILE)
|
|
assert len(filter_term_rows(rows, "")) == 3
|
|
assert filter_term_rows(rows, "chuxx") == [("À masquer", "CHUXX", "Standard local")]
|
|
assert filter_term_rows(rows, "conserver") == [
|
|
r for r in rows if r[0] == "À conserver"
|
|
]
|
|
assert filter_term_rows(rows, "zzz") == []
|
|
|
|
|
|
# --- Smokes headless (fenêtre tableau + infobulle) --------------------------
|
|
|
|
@pytest.fixture
|
|
def ctk_root():
|
|
ctk = pytest.importorskip("customtkinter")
|
|
try:
|
|
root = ctk.CTk()
|
|
except Exception as exc:
|
|
pytest.skip(f"display Tk indisponible: {exc}")
|
|
root.withdraw()
|
|
try:
|
|
yield root
|
|
finally:
|
|
try:
|
|
root.destroy()
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
def test_terms_table_window_filters_and_disables_add(ctk_root):
|
|
from gui_v6 import theme as theme_mod
|
|
from gui_v6.terms_table_window import TermsTableWindow
|
|
|
|
p = theme_mod.get_palette(theme_mod.DEFAULT_THEME)
|
|
win = TermsTableWindow(ctk_root, p, profile_term_rows(_PROFILE), profile_label="Standard local")
|
|
ctk_root.update_idletasks()
|
|
assert win.visible_count() == 3
|
|
assert win.add_is_disabled() # action non câblée → désactivée
|
|
win.set_query("chuxx")
|
|
assert win.visible_count() == 1
|
|
win.set_query("")
|
|
assert win.visible_count() == 3
|
|
win.destroy()
|
|
|
|
|
|
def test_attach_tooltip_does_not_break_widget(ctk_root):
|
|
import customtkinter as ctk
|
|
|
|
from gui_v6 import ui_kit
|
|
|
|
lbl = ctk.CTkLabel(ctk_root, text="x")
|
|
lbl.pack()
|
|
ctk_root.update_idletasks()
|
|
tip = ui_kit.attach_tooltip(lbl, "aide contextuelle")
|
|
tip.show()
|
|
ctk_root.update_idletasks()
|
|
tip.hide()
|
|
assert lbl.winfo_exists()
|
|
|
|
|
|
def test_subtabs_no_profils_subtab():
|
|
"""Retour Dom : le sous-onglet Profils (doublon non câblé) est retiré."""
|
|
from gui_v6.tabs.tab_config import _SUBTABS
|
|
|
|
keys = [k for k, _ in _SUBTABS]
|
|
labels = [lbl for _, lbl in _SUBTABS]
|
|
assert "pro" not in keys
|
|
assert not any("Profils" in lbl for lbl in labels)
|
|
|
|
|
|
def _all_texts(widget):
|
|
out = []
|
|
try:
|
|
out.append(str(widget.cget("text")))
|
|
except Exception:
|
|
pass
|
|
for child in widget.winfo_children():
|
|
out += _all_texts(child)
|
|
return out
|
|
|
|
|
|
def test_reglages_labels_renamed_and_profile_readable(ctk_root, tmp_path, monkeypatch):
|
|
from gui_v6.tabs import tab_config
|
|
|
|
monkeypatch.setattr(tab_config, "_app_base_dir", lambda: tmp_path)
|
|
tab = tab_config.ConfigTab(ctk_root)
|
|
tab.update_idletasks()
|
|
|
|
texts = " | ".join(_all_texts(tab))
|
|
assert "Profil d'anonymisation" in texts # addendum : renommage
|
|
assert "Profil métier" not in texts
|
|
assert "Dossier de sortie" in texts # addendum : « Sortie… » clarifié
|
|
|
|
# retour Dom : accès direct au tableau depuis Réglages, plus de pastilles inline
|
|
assert "Ouvrir le tableau des termes" in texts
|
|
assert "Voir le profil" not in texts
|
|
assert "FUROSEMIDE" not in texts # plus de pastilles de termes exemple inline
|
|
|
|
# profil lisible : résumé avec les 3 listes
|
|
summary = tab._active_profile_summary()
|
|
assert set(summary.list_counts.keys()) == {"À conserver", "À masquer", "À ignorer"}
|
|
|
|
# tableau des termes ouvrable DIRECTEMENT depuis Réglages (sans onglet Profils)
|
|
tab._open_terms_table()
|
|
tab.update_idletasks()
|
|
tab.destroy()
|
|
|
|
|
|
def test_usage_tab_finish_calls_reporter(ctk_root):
|
|
"""Câblage : la fin de run appelle le reporter de télémétrie (non bloquant)."""
|
|
import threading
|
|
|
|
from gui_v6.processing_runner import RunSummary
|
|
from gui_v6.tabs.tab_usage import UsageTab
|
|
|
|
called = threading.Event()
|
|
captured = {}
|
|
|
|
def reporter(summary):
|
|
captured["summary"] = summary
|
|
called.set()
|
|
|
|
tab = UsageTab(ctk_root, usage_reporter=reporter)
|
|
ctk_root.update_idletasks()
|
|
summary = RunSummary(total=1, succeeded=1)
|
|
tab._finish(summary)
|
|
assert called.wait(timeout=3.0) # reporter appelé en thread daemon
|
|
assert captured["summary"] is summary
|
|
tab.destroy()
|