Live 30.10.: ESC at 11:03:09 set all stop files, yet the runner clicked "max" and "buyin" at 11:03:12 - stellen_klicken checked only before a sequence, the mouse path never, and cleanup clicked sitout/cross "trotz_stopp". hand/notaus.py is now the one source for the stop files (act, click, stopp); click.click checks before start, on every movement step and before pressing (KlickNotAus), pid_klick too, sequences check before each click, trotz_stopp no longer overrides Not-Aus, dialog.esc sends no key and the live pointer stops. The runner logs "nicht geklickt (Not-Aus)" instead of a sitout it did not do. The header counted every window of a table process (table + dialog = 2); it now counts rooms from the process list. Tests get their own stop folder (POKERFREAK_STOPP_ORDNER) so they never see or touch the machine's Not-Aus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
194 lines
7.3 KiB
Python
194 lines
7.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Not-Aus heisst: keine Eingabe mehr - keine Mausbewegung, kein Klick, keine Taste (hand/notaus.py).
|
|
|
|
Live 30.10. 11:03:09 ESC (Not-Aus, beide Dateien gesetzt), 11:03:12 klickte der Läufer noch
|
|
"max" und "buyin": stellen_klicken prüfte nur vor der Folge, die Mausbewegung gar nicht, und
|
|
beim Beenden klickte er Sitout und Kreuz ausdrücklich "trotz_stopp".
|
|
|
|
* hand/notaus.aktiv(): eine der Stopp-Dateien (scratch/, hand/scratch/, betrieb/scratch/) da.
|
|
* click.click: vor dem Start, bei jedem Schritt der Bewegung und vor dem Drücken - ist Not-Aus
|
|
aktiv, geht nichts mehr raus (KlickNotAus, ein FensterNichtVorn). pid_klick ebenso.
|
|
* act.stellen_klicken: vor jedem Klick der Folge; `trotz_stopp` gilt bei Not-Aus nicht.
|
|
* dialog.esc: keine Taste bei Not-Aus.
|
|
* Der lebende Zeiger (hand/zeiger.Lauf) bewegt bei Not-Aus nichts - auch nicht, wenn er schon lief.
|
|
|
|
python3 tests/notaus_spec.py -v
|
|
"""
|
|
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, "hand")):
|
|
_w = os.path.dirname(_w)
|
|
for _u in ("hand", "lesen", "mcp"):
|
|
sys.path.insert(0, os.path.join(_w, _u))
|
|
|
|
import act
|
|
import click
|
|
import dialog
|
|
import notaus
|
|
import stopp
|
|
|
|
FENSTER = {"pid": 42, "rect": (100, 100, 800, 600)}
|
|
|
|
|
|
class Dateien(unittest.TestCase):
|
|
def test_eine_datei_genuegt(self):
|
|
ordner = tempfile.mkdtemp()
|
|
alt = notaus.PFADE
|
|
notaus.PFADE = [os.path.join(ordner, n) for n in ("a", "b")]
|
|
try:
|
|
self.assertFalse(notaus.aktiv())
|
|
open(notaus.PFADE[1], "w").close()
|
|
self.assertTrue(notaus.aktiv())
|
|
finally:
|
|
notaus.PFADE = alt
|
|
|
|
def test_dieselben_dateien_wie_das_cockpit(self):
|
|
self.assertEqual(sorted(stopp.STOPP_PFADE), sorted(notaus.PFADE))
|
|
if not os.environ.get("POKERFREAK_STOPP_ORDNER"): # ohne Test-Ordner: die der App
|
|
self.assertEqual(sorted(p.replace(notaus.WURZEL + "/", "") for p in notaus.PFADE),
|
|
["betrieb/scratch/stop", "hand/scratch/stop", "scratch/stop"])
|
|
|
|
|
|
class Schalter:
|
|
"""notaus.aktiv() schaltet nach `nach` Abfragen auf an."""
|
|
|
|
def __init__(self, nach):
|
|
self.n, self.nach = 0, nach
|
|
|
|
def __call__(self):
|
|
self.n += 1
|
|
return self.n > self.nach
|
|
|
|
|
|
class Klick(unittest.TestCase):
|
|
def setUp(self):
|
|
self.alt = (click._senden, click._senden_an, click.vorn_sicherstellen, click.zeiger, click.vorne_pid,
|
|
click._time.sleep, click.maus.plan, notaus.aktiv)
|
|
self.gesendet = []
|
|
click._senden = lambda art, x, y: self.gesendet.append((art, x, y))
|
|
click._senden_an = lambda pid, art, x, y: self.gesendet.append((art, x, y))
|
|
click.vorn_sicherstellen = lambda f: None
|
|
click.zeiger = lambda: (0.0, 0.0)
|
|
click.vorne_pid = lambda: 42
|
|
click._time.sleep = lambda s: None
|
|
click.maus.plan = lambda start, ziel, halb, rng: ([(i, 200.0 + i, 200.0) for i in range(10)] + [(10,) + ziel], 0, 0)
|
|
|
|
def tearDown(self):
|
|
(click._senden, click._senden_an, click.vorn_sicherstellen, click.zeiger, click.vorne_pid,
|
|
click._time.sleep, click.maus.plan, notaus.aktiv) = self.alt
|
|
|
|
def test_vorher_aktiv_nichts(self):
|
|
notaus.aktiv = lambda: True
|
|
with self.assertRaises(click.KlickNotAus):
|
|
click.click(500, 400, fenster=FENSTER)
|
|
self.assertEqual(self.gesendet, [])
|
|
|
|
def test_mitten_in_der_bewegung_kein_druck(self):
|
|
notaus.aktiv = Schalter(nach=4)
|
|
with self.assertRaises(click.KlickNotAus):
|
|
click.click(500, 400, fenster=FENSTER)
|
|
self.assertNotIn(click.DOWN, [a for a, _, _ in self.gesendet])
|
|
self.assertLess(len(self.gesendet), 11) # die Bewegung hielt an
|
|
|
|
def test_vor_dem_druecken(self):
|
|
notaus.aktiv = Schalter(nach=12) # Start + 11 Schritte frei, dann an
|
|
with self.assertRaises(click.KlickNotAus):
|
|
click.click(500, 400, fenster=FENSTER)
|
|
self.assertNotIn(click.DOWN, [a for a, _, _ in self.gesendet])
|
|
|
|
def test_ohne_not_aus_klickt_er(self):
|
|
notaus.aktiv = lambda: False
|
|
click.click(500, 400, fenster=FENSTER)
|
|
self.assertIn((click.DOWN, 500, 400), self.gesendet)
|
|
|
|
def test_ohne_maus_ebenso(self):
|
|
notaus.aktiv = lambda: True
|
|
with self.assertRaises(click.KlickNotAus):
|
|
click.pid_klick(500, 400, FENSTER)
|
|
self.assertEqual(self.gesendet, [])
|
|
|
|
def test_wird_wie_ein_verweigerter_klick_gefangen(self):
|
|
self.assertTrue(issubclass(click.KlickNotAus, click.FensterNichtVorn))
|
|
|
|
|
|
class Folge(unittest.TestCase):
|
|
def setUp(self):
|
|
self.alt = (act._klicken, notaus.aktiv)
|
|
self.geklickt = []
|
|
act._klicken = lambda px, py, f, halb, rng=None, wie=None: self.geklickt.append((px, py))
|
|
|
|
def tearDown(self):
|
|
act._klicken, notaus.aktiv = self.alt
|
|
|
|
def test_not_aus_zwischen_max_und_buyin(self):
|
|
stand = {"aus": False}
|
|
notaus.aktiv = lambda: stand["aus"]
|
|
act._klicken = lambda px, py, f, halb, rng=None, wie=None: (self.geklickt.append((px, py)),
|
|
stand.update(aus=True))
|
|
g = act.stellen_klicken(FENSTER, [("max", (0.5, 0.5)), ("buyin", (0.6, 0.6))], pause=(0, 0))
|
|
self.assertEqual(g, ["max"])
|
|
self.assertEqual(len(self.geklickt), 1)
|
|
|
|
def test_trotz_stopp_gilt_bei_not_aus_nicht(self):
|
|
notaus.aktiv = lambda: True
|
|
self.assertEqual(act.stellen_klicken(FENSTER, [("sitout", (0.1, 0.1))], trotz_stopp=True), [])
|
|
self.assertEqual(self.geklickt, [])
|
|
|
|
def test_gestoppt_ist_not_aus(self):
|
|
notaus.aktiv = lambda: True
|
|
self.assertTrue(act.gestoppt())
|
|
|
|
|
|
class Taste(unittest.TestCase):
|
|
def test_kein_esc_bei_not_aus(self):
|
|
alt = notaus.aktiv
|
|
notaus.aktiv = lambda: True
|
|
try:
|
|
self.assertFalse(dialog.esc({"pid": 42, "rect": (0, 0, 10, 10)}))
|
|
finally:
|
|
notaus.aktiv = alt
|
|
|
|
|
|
class LebenderZeiger(unittest.TestCase):
|
|
def setUp(self):
|
|
import random
|
|
import time
|
|
import zeiger
|
|
self.time, self.zeiger = time, zeiger
|
|
self.alt = notaus.aktiv
|
|
self.aus = {"an": False}
|
|
notaus.aktiv = lambda: self.aus["an"]
|
|
self.gesendet = []
|
|
kasten = os.path.join(tempfile.mkdtemp(), "auftraege.jsonl")
|
|
self.lauf = zeiger.Lauf(lambda x, y: self.gesendet.append((x, y)),
|
|
lambda: self.gesendet[-1] if self.gesendet else (600.0, 400.0),
|
|
(0.0, 0.0, 1200.0, 860.0), rng=random.Random(1), briefkasten=kasten)
|
|
|
|
def tearDown(self):
|
|
self.lauf.stoppen()
|
|
notaus.aktiv = self.alt
|
|
|
|
def test_bei_not_aus_keine_bewegung(self):
|
|
self.aus["an"] = True
|
|
self.lauf.starten()
|
|
self.time.sleep(3.0)
|
|
self.assertEqual(self.gesendet, [])
|
|
|
|
def test_not_aus_haelt_den_laufenden_zeiger_an(self):
|
|
self.lauf.starten()
|
|
self.time.sleep(3.0)
|
|
self.assertTrue(self.gesendet, "der Zeiger lebt nicht")
|
|
self.aus["an"] = True
|
|
self.time.sleep(0.2)
|
|
n = len(self.gesendet)
|
|
self.time.sleep(1.5)
|
|
self.assertEqual(len(self.gesendet), n)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|