Files
pokerfreak/tests/sicht_steuern_spec.py
T
mmintel 9c79d8236b Acceptance 5.11.: channel play without AFK, quiet focus, working Cockpit, stronger play
- Practice tables: 20-min session 54/54 turns at the server, control session 28 turns,
  0 timeouts; stage: 3 tables, two rounds each, clean teardown.
- Never let the clock run: an engine abstention becomes check or fold (nie_verstreichen).
- Mittler join in a fixed order (kill the duplicate, then announce), a mittler ends with its
  game, the laufwache opens no tables, stop waits for the runner to stand up.
- Focus: no lobby connections from HUD, probes or layout; "Focus Window on Turn" off.
- Tables: disconnected or sitting-out opponents do not count; a table without channel is
  closed and avoided after 45 s; the join event keeps the writer's pid (strict invariants).
- Geldwache: same room list as the runner, the table's own report, stand up before closing.
- Engine: the small blind completes the top 65 % against limpers (price per fair share);
  the calling range of a bet is as wide as the villain calls - value bets into stations.
- Cockpit: the source tree never comes from SHELL; one operating set for laufwache and
  Cockpit (sicht/start.py --client, ServerStart).
- Project lives in ~/Projects/pokerfreak (kern was a detour).
2026-11-05 16:10:43 +01:00

118 lines
4.4 KiB
Python

#!/usr/bin/env python3
"""Knöpfe des Cockpits mit Daten (sicht/steuern.py): Spielplan setzen, Statistik zurücksetzen.
* spielplan_setzen schreibt betrieb/scratch/spielplan.json (betrieb/spielplan.py) - Unsinn nie
* statistik_zuruecksetzen setzt je Modus einen Nullpunkt, ab_anfang nimmt ihn zurück; das
Archiv bleibt unberührt
* der Server reicht {aktion, raum?, daten?} durch; daten muss ein Objekt sein
python3 tests/sicht_steuern_spec.py -v
"""
import json
import os
import sys
import tempfile
import unittest
_w = os.path.dirname(os.path.abspath(__file__))
while _w != "/" and not os.path.isdir(os.path.join(_w, "lesen")):
_w = os.path.dirname(_w)
for _u in ("sicht", "betrieb", "lesen"):
sys.path.insert(0, os.path.join(_w, _u))
import spielplan
import steuern
class MitDaten(unittest.TestCase):
def setUp(self):
self.ordner = tempfile.TemporaryDirectory()
self.alt = (steuern.SPIELPLAN, steuern.NULLPUNKTE)
steuern.SPIELPLAN = os.path.join(self.ordner.name, "spielplan.json")
steuern.NULLPUNKTE = os.path.join(self.ordner.name, "statistik.json")
def tearDown(self):
steuern.SPIELPLAN, steuern.NULLPUNKTE = self.alt
self.ordner.cleanup()
def test_spielplan_setzen(self):
r = steuern.ausfuehren("spielplan_setzen", daten={"modus": "cash", "tische": 3, "budget": 250})
self.assertTrue(r["ok"], r)
self.assertEqual(spielplan.lesen(steuern.SPIELPLAN), spielplan.Spielplan("cash", 3, 250.0))
self.assertIn("Cash", r["text"])
def test_spielplan_unsinn_schreibt_nichts(self):
r = steuern.ausfuehren("spielplan_setzen", daten={"modus": "turnier", "tische": 3})
self.assertFalse(r["ok"])
self.assertFalse(os.path.exists(steuern.SPIELPLAN))
self.assertFalse(steuern.ausfuehren("spielplan_setzen")["ok"])
def test_statistik_nullpunkt_und_zurueck(self):
r = steuern.ausfuehren("statistik_zuruecksetzen", daten={"modus": "uebung"})
self.assertTrue(r["ok"], r)
with open(steuern.NULLPUNKTE) as f:
n = json.load(f)
self.assertIsInstance(n["uebung"], float)
self.assertNotIn("cash", n)
self.assertTrue(steuern.ausfuehren("statistik_ab_anfang", daten={"modus": "uebung"})["ok"])
with open(steuern.NULLPUNKTE) as f:
self.assertEqual(json.load(f), {})
self.assertFalse(steuern.ausfuehren("statistik_zuruecksetzen", daten={"modus": "x"})["ok"])
def test_alte_knoepfe_ohne_daten(self):
self.assertIn("aktion", steuern.ausfuehren("unbekannt"))
class StreamerModus(unittest.TestCase):
"""'Streamer-Modus (Maus)' an und aus: die Schalterdatei des Kanals, nichts anderes."""
def setUp(self):
self.ordner = tempfile.TemporaryDirectory()
import umgebung
self.alt = umgebung.MAUS_FLAG
umgebung.MAUS_FLAG = os.path.join(self.ordner.name, "maus")
def tearDown(self):
import umgebung
umgebung.MAUS_FLAG = self.alt
self.ordner.cleanup()
def test_an_schreibt_den_schalter(self):
r = steuern.ausfuehren("maus_setzen", daten={"an": True})
self.assertTrue(r["ok"], r)
self.assertTrue(os.path.exists(self.flag()), "die Datei existiert")
self.assertTrue(__import__("umgebung").maus(), "die Welt sieht den Schalter")
def test_aus_nimmt_den_schalter_wieder(self):
self.assertTrue(steuern.ausfuehren("maus_setzen", daten={"an": True})["ok"])
r = steuern.ausfuehren("maus_setzen", daten={"an": False})
self.assertTrue(r["ok"], r)
self.assertFalse(os.path.exists(self.flag()), "die Datei ist weg")
self.assertFalse(__import__("umgebung").maus())
def test_ohne_daten_ist_kein_schalter(self):
r = steuern.ausfuehren("maus_setzen")
self.assertFalse(r["ok"])
self.assertFalse(os.path.exists(self.flag()))
@staticmethod
def flag():
import umgebung
return umgebung.MAUS_FLAG
class Knoepfe(unittest.TestCase):
"""Der Knopfplan: jede bekannte Aktion antwortet, jede unbekannte nicht."""
def test_nach_vorn_ist_zurueck_im_plan(self):
"""Der Knopf steht seit FOO ohne Serverseite im Cockpit ('unbekannte Aktion') - die
Aktion ist wieder da."""
self.assertIn("tische_vorn", steuern.AKTIONEN)
r = steuern.ausfuehren("tische_vorn")
self.assertEqual(r["aktion"], "tische_vorn")
self.assertIn("ok", r)
if __name__ == "__main__":
unittest.main()