"""Le corpus versionné de la base de connaissances : présent, propre, sans rien d'interne (spec §3, §6).""" import re import unittest from pathlib import Path from base_connaissances.decoupage import lire_corpus CORPUS = Path(__file__).resolve().parents[1] / "base_connaissances" / "corpus" STATIONS = ["BREITHORN", "CLARIDEN", "FLORIDA", "JUNGFRAU", "LENZSPITZE", "MICHIGAN", "NADELHORN", "NEBRASKA", "NIEDERHORN", "NORDEND", "SNCF01", "SUSTENHORN", "WILDSTRUBEL", "VERMONT"] INTERDITS = ["python3", "agent-tools", ".py", "Marc", "Barcelone", "Vaud", "GN-1", "GN-5", "seuil provisoire", "seuils provisoires"] class TestCorpus(unittest.TestCase): def test_corpus_present(self): self.assertGreaterEqual(len(lire_corpus(CORPUS)), 60) def test_titres_uniques_et_contenus_non_vides(self): x = lire_corpus(CORPUS) self.assertEqual(len({e.titre for e in x}), len(x)) self.assertTrue(all(e.contenu.strip() and e.source.strip() for e in x)) def test_taille_raisonnable(self): trop_longs = [e.cle for e in lire_corpus(CORPUS) if len(e.contenu) > 8000] self.assertEqual(trop_longs, []) def test_rien_d_interne(self): for e in lire_corpus(CORPUS): texte = e.titre + "\n" + e.contenu for s in STATIONS: self.assertIsNone(re.search(rf"\b{s}\b", texte, re.I), f"{s} dans {e.cle}") for i in INTERDITS: self.assertNotIn(i.lower(), texte.lower(), f"{i} dans {e.cle}") def test_instructions_presentes(self): texte = (CORPUS.parent / "instructions.md").read_text() self.assertIn("langue du client", texte) self.assertLessEqual(len(texte), 4000) if __name__ == "__main__": unittest.main()