#!/usr/bin/env python3 """Tara als Generator fuer den Sprecher (betrieb/tara_lehrer.py). Geprueft: aus einer LLM-Wahl entsteht ein Generator (oder None ohne Sprachmodell), und `erzeugen` reicht die Lage an lehrer_llm.kommentar durch - ein Ausfall bleibt still (kein statischer Ausweichtext). python3 tests/tara_lehrer_spec.py -v """ import json import os import sys import unittest _w = os.path.dirname(os.path.abspath(__file__)) while _w != "/" and not os.path.isdir(os.path.join(_w, "betrieb")): _w = os.path.dirname(_w) sys.path.insert(0, os.path.join(_w, "betrieb")) import tara_lehrer LLM = {"anbieter": "openai-kompatibel", "adresse": "http://127.0.0.1:11434/v1", "modell": "x"} def antwort(text): return lambda url, kopf, daten: json.dumps({"choices": [{"message": {"content": text}}]}).encode("utf-8") def ausfall(*_a, **_k): raise ConnectionError("kein Dienst") class AusWahl(unittest.TestCase): def test_ohne_llm_keine_tara(self): for wahl in ({"anbieter": "aus"}, {"anbieter": ""}, {}, "quatsch", None): with self.subTest(wahl=wahl): self.assertIsNone(tara_lehrer.TaraLehrer.aus_wahl(wahl)) def test_mit_llm_ein_generator(self): t = tara_lehrer.TaraLehrer.aus_wahl(LLM) self.assertIsInstance(t, tara_lehrer.TaraLehrer) self.assertEqual(t.wahl["adresse"], LLM["adresse"]) class Erzeugen(unittest.TestCase): def test_saubere_zeile_kommt_durch(self): t = tara_lehrer.TaraLehrer(LLM, senden=antwort("Blinds, meet thief.")) self.assertEqual(t.erzeugen("You are raising on the button."), "Blinds, meet thief.") def test_regelverstoss_bleibt_still(self): t = tara_lehrer.TaraLehrer(LLM, senden=antwort("I raise to 2 big blinds")) self.assertEqual(t.erzeugen("x"), "") def test_ausfall_bleibt_still_kein_fallback(self): t = tara_lehrer.TaraLehrer(LLM, senden=ausfall) self.assertEqual(t.erzeugen("x"), "") def test_leere_lage_fragt_nichts(self): t = tara_lehrer.TaraLehrer(LLM, senden=antwort("egal")) self.assertEqual(t.erzeugen(""), "") if __name__ == "__main__": unittest.main(verbosity=2)