Files
pokerfreak/tests/schnittstelle_spec.py
mmintel f2650dc3be Cockpit and runner 5.11. late: no ESC stop, hidden tables stay open, gapless tiling, teacher core
- ESC no longer triggers the emergency stop (an ESC in another app stopped the run at 20:29);
  stopping only via ctrl-opt-cmd-S or the stop button
- a table whose program runs counts as open even when its window is not visible (other
  desktop, Cockpit without screen recording): no reopening, no giving up, correct table
  count; teardown and closing a full table work over the channel
- Cockpit checks and requests the screen recording permission
- gapless tiling (sicht/kacheln.py): tables fill the full height, the Cockpit bar takes the
  rest and never goes below its minimum width; own animated resize no longer stored as minimum
- earlier today: top-up safety net, leave after the hand (sit out next hand), tournament lock,
  waitlist left on close, Cockpit start lock, warning throttle, preflop raise-war reading,
  Bomb Pot practice, tournament break and level-up on the stage
- teacher core for the streamer mode (betrieb/lehrer.py, betrieb/grund_lesen.py) and its plan
2026-11-05 22:39:41 +01:00

135 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""Der Vertrag zwischen Welt und Engine: fuenf Beruehrungen, mehr kreuzt nicht (docs/SCHNITTSTELLE.md).
Diese Pruefung haelt die Naht fest. Faellt sie, hat jemand eine Beruehrung verschoben, ohne das
Dokument und diesen Fall zu aendern - dann bricht beim Trennen der Baeume der Weg.
python3 tests/schnittstelle_spec.py -v
"""
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, "lesen")):
_w = os.path.dirname(_w)
WURZEL = _w
for _u in ("hand", "client", "lesen", "betrieb", "sicht", "mock"):
_q = os.path.join(WURZEL, _u)
if _q not in sys.path:
sys.path.insert(0, _q)
import pipe # noqa: E402
import quellen # noqa: E402
import steuern # noqa: E402
import umgebung # noqa: E402
class Adresse(unittest.TestCase):
"""1. Die Welt stellt einen Client hin - Adresse und Sockets sind die Beruehrung."""
def test_ohne_ausdrueckliches_0_ist_die_welt_dran(self):
# die Spur setzt CDP_PORT=1; hier soll die Vorgabe gelten
alt = os.environ.pop("CLIENT", None)
alt_cdp = os.environ.pop("CDP_PORT", None)
alt_log = os.environ.pop("COINPOKER_LOG", None)
try:
self.assertTrue(umgebung.klon(), "Vorgabe muss die Welt sein")
self.assertEqual(umgebung.log(), umgebung.KLON_LOG)
self.assertEqual(umgebung.cdp_port(), umgebung.KLON_CDP)
finally:
for k, v in (("CLIENT", alt), ("CDP_PORT", alt_cdp), ("COINPOKER_LOG", alt_log)):
if v is None:
os.environ.pop(k, None)
else:
os.environ[k] = v
def test_ein_genanntes_log_zeigt_auf_den_client(self):
merken = {k: os.environ.pop(k, None) for k in ("CLIENT", "COINPOKER_LOG", "CDP_PORT")}
os.environ["COINPOKER_LOG"] = "/irgendwo/client.log"
try:
self.assertFalse(umgebung.klon())
self.assertEqual(umgebung.log(), "/irgendwo/client.log")
finally:
for k, v in merken.items():
if v is None:
os.environ.pop(k, None)
else:
os.environ[k] = v
def test_ausdrueckliche_angaben_gehen_vor(self):
umg = dict(os.environ, COINPOKER_LOG="/irgendwo/x.log", CDP_PORT="1234")
alt = os.environ.copy()
os.environ.update(COINPOKER_LOG="/irgendwo/x.log", CDP_PORT="1234")
try:
self.assertEqual(umgebung.log(), "/irgendwo/x.log")
self.assertEqual(umgebung.cdp_port(), 1234)
finally:
os.environ.clear()
os.environ.update(alt)
self.assertIn("COINPOKER_LOG", umg)
def test_zwei_sockets_mit_festen_namen(self):
self.assertTrue(pipe.pfad("Big Ben 123456", tmp="/tmp").endswith("/tmp/Big Ben 123456"))
self.assertTrue(pipe.lobby_pfad("/tmp").startswith("/tmp/lobby-pipe"),
"die Lobby darf auf lobby-pipe-<n> ausweichen, der Name bleibt")
self.assertEqual(pipe.LOBBY, "lobby-pipe")
class Treffpunkt(unittest.TestCase):
"""2. bis 4. Ein Verzeichnis, feste Dateinamen darin."""
def test_treffpunkt_ist_uebersteuerbar(self):
alt = os.environ.get("SCRATCH")
os.environ["SCRATCH"] = "/tmp/treffpunkt"
try:
self.assertEqual(quellen.treffpunkt(), "/tmp/treffpunkt")
self.assertEqual(steuern.treffpunkt(), "/tmp/treffpunkt")
finally:
if alt is None:
os.environ.pop("SCRATCH", None)
else:
os.environ["SCRATCH"] = alt
def test_vorgabe_ist_der_eigene_baum(self):
alt = os.environ.pop("SCRATCH", None)
try:
erwartet = os.path.join(WURZEL, "betrieb", "scratch")
if not os.path.isdir(os.path.join(WURZEL, "betrieb")):
erwartet = os.path.join(WURZEL, "scratch") # ohne betrieb/ heisst er scratch/
self.assertEqual(quellen.treffpunkt(), erwartet)
finally:
if alt is not None:
os.environ["SCRATCH"] = alt
def test_protokoll_und_steuerdateien_haben_feste_namen(self):
t = quellen.treffpunkt()
self.assertEqual(quellen.SCHATTEN, os.path.join(t, "shadow.jsonl"))
self.assertEqual(quellen.STROM, os.path.join(t, "strom.jsonl"))
self.assertEqual(steuern.SPIELPLAN, os.path.join(t, "spielplan.json"))
self.assertTrue(steuern.AUSWEICHEN.endswith("ausweichen"))
class Befehl(unittest.TestCase):
"""5. Die Welt startet die Engine - als Kommando, nicht als Pfad."""
def test_engine_ist_ein_kommando(self):
# Die Vorgabe zeigt in den eigenen Baum; in der Welt zeigt ENGINE daneben.
self.assertIn("runner.py", steuern.ENGINE)
self.assertEqual(steuern.engine_befehl()[-1], "--act")
def test_engine_ist_uebersteuerbar(self):
alt = os.environ.get("ENGINE")
os.environ["ENGINE"] = "python3 /wo/auch/immer/engine.py"
try:
self.assertEqual(steuern.engine_befehl(), ["python3", "/wo/auch/immer/engine.py", "--act"])
finally:
if alt is None:
os.environ.pop("ENGINE", None)
else:
os.environ["ENGINE"] = alt
if __name__ == "__main__":
unittest.main()