Files
aimsight-libredesk/tests/test_taches.py
T

64 lines
2.6 KiB
Python

"""Les tâches VS Code : aucune n'écrit en production sans adresse tapée et confirmation (design §5)."""
import json
import re
import unittest
from pathlib import Path
DEPOT = Path(__file__).resolve().parents[1]
TACHES = DEPOT / ".vscode" / "tasks.json"
CONFIRMATION_PRODUCTION = '[ "${input:confirmationProduction}" = oui ]'
def charger() -> dict:
return json.loads(TACHES.read_text(encoding="utf-8"))
def commandes() -> dict[str, str]:
return {t["label"]: t["command"] for t in charger()["tasks"]}
class TestTaches(unittest.TestCase):
def test_json_valide_et_libelles_uniques(self):
libelles = [t["label"] for t in charger()["tasks"]]
self.assertEqual(len(libelles), len(set(libelles)))
self.assertIn("Tests", libelles)
def test_ecriture_production_demande_confirmation(self):
ecritures = {l: c for l, c in commandes().items() if "--ecrire" in c and "urlProduction" in c}
self.assertTrue(ecritures, "aucune tâche d'écriture en production trouvée")
for libelle, c in ecritures.items():
self.assertIn(CONFIRMATION_PRODUCTION, c, libelle)
self.assertLess(c.index(CONFIRMATION_PRODUCTION), c.index("--ecrire"), libelle)
def test_url_production_sans_defaut(self):
entree = next(i for i in charger()["inputs"] if i["id"] == "urlProduction")
self.assertNotIn("default", entree)
def test_confirmations_non_par_defaut(self):
for i in charger()["inputs"]:
if i["id"].startswith("confirmation"):
self.assertEqual(i["default"], "non", i["id"])
def test_taches_instance_de_test_ne_visent_pas_la_production(self):
for libelle, c in commandes().items():
if "instance de test" in libelle.lower():
self.assertNotIn("urlProduction", c, libelle)
def test_import_instance_de_test_lit_son_env(self):
for libelle, c in commandes().items():
if "base_connaissances.importer" in c and "instance de test" in libelle.lower():
self.assertIn("instance-de-test/.env", c, libelle)
def test_effacer_l_instance_demande_confirmation(self):
c = next(c for l, c in commandes().items() if "down -v" in c)
self.assertIn('[ "${input:confirmation}" = oui ]', c)
def test_scripts_references_existent(self):
for libelle, c in commandes().items():
for chemin in re.findall(r"(?:instance-de-test|ollama)/[\w.-]+\.(?:py|sh|yml)", c):
self.assertTrue((DEPOT / chemin).exists(), f"{chemin} ({libelle})")
if __name__ == "__main__":
unittest.main()