Live 30.10. the bot clicked the Practice tab it was already on and the user saw clicks beside the window. Lobby: read the active tab (.active-tab, measured) and click only if needed, then verify it switched; never Join a table whose window is open (fill and self-heal). A real mouse click is only sent when the point and its scattered end lie inside the target window (KlickAusserhalb, a FensterNichtVorn), and not at all without a lobby window. Two mcp_server_spec tests patched the wrong name and clicked the real lobby with the real mouse whenever CoinPoker ran - they now patch lobby_adapter and demand an opened table; tests/lauf.py blocks the real debug port for every spec. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.2 KiB
Python
85 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Ein echter Mausklick nur im Zielfenster (hand/click.click, hand/eingabe.lobby_maus_klick).
|
|
|
|
Live 30.10.: der Bot klickte mehrfach neben das Fenster. Regeln:
|
|
* Mit `fenster` (samt `rect` x, y, w, h): liegt der Mittelpunkt oder der gestreute Endpunkt
|
|
ausserhalb, wird gar nichts gesendet - weder Bewegung noch Druck - und KlickAusserhalb gemeldet
|
|
(ein FensterNichtVorn: Läufer und act fangen es wie jeden verweigerten Klick).
|
|
* Lobby: ohne erkanntes Lobbyfenster kein Mausklick.
|
|
|
|
python3 tests/klick_ziel_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, "hand")):
|
|
_w = os.path.dirname(_w)
|
|
for _u in ("hand", "lesen"):
|
|
sys.path.insert(0, os.path.join(_w, _u))
|
|
|
|
import click
|
|
import eingabe
|
|
|
|
FENSTER = {"pid": 42, "rect": (100, 100, 800, 600)}
|
|
|
|
|
|
class ImFenster(unittest.TestCase):
|
|
def setUp(self):
|
|
self.alt = (click._senden, click.vorn_sicherstellen, click.zeiger, click.vorne_pid, click._time.sleep,
|
|
click.maus.plan)
|
|
self.gesendet = []
|
|
click._senden = lambda 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
|
|
self.ende = None
|
|
click.maus.plan = lambda start, ziel, halb, rng: ([(0, 50.0, 50.0), (10,) + (self.ende or ziel)], 0, 0)
|
|
|
|
def tearDown(self):
|
|
(click._senden, click.vorn_sicherstellen, click.zeiger, click.vorne_pid, click._time.sleep,
|
|
click.maus.plan) = self.alt
|
|
|
|
def test_im_fenster_wird_geklickt(self):
|
|
click.click(500, 400, fenster=FENSTER)
|
|
self.assertIn((click.DOWN, 500, 400), self.gesendet)
|
|
|
|
def test_ausserhalb_kein_ereignis(self):
|
|
with self.assertRaises(click.KlickAusserhalb):
|
|
click.click(950, 400, fenster=FENSTER)
|
|
self.assertEqual(self.gesendet, [])
|
|
|
|
def test_gestreuter_endpunkt_ausserhalb_kein_ereignis(self):
|
|
self.ende = (901.0, 400.0)
|
|
with self.assertRaises(click.KlickAusserhalb):
|
|
click.click(899, 400, fenster=FENSTER)
|
|
self.assertEqual(self.gesendet, [])
|
|
|
|
def test_wird_wie_ein_verweigerter_klick_gefangen(self):
|
|
self.assertTrue(issubclass(click.KlickAusserhalb, click.FensterNichtVorn))
|
|
|
|
def test_rand_zaehlt_dazu(self):
|
|
click.click(100, 100, fenster=FENSTER)
|
|
self.assertIn((click.DOWN, 100, 100), self.gesendet)
|
|
|
|
|
|
class Lobby(unittest.TestCase):
|
|
def test_ohne_lobbyfenster_kein_klick(self):
|
|
import fenster
|
|
alt = (fenster.alle, eingabe._click)
|
|
geklickt = []
|
|
fenster.alle = lambda: [{"tischfenster": True, "pid": 7, "rect": (0, 0, 10, 10)}]
|
|
eingabe._click = lambda: type("C", (), {"click": staticmethod(lambda *a, **k: geklickt.append(a))})
|
|
try:
|
|
self.assertFalse(eingabe.lobby_maus_klick(300, 300))
|
|
self.assertIn("nicht geklickt", eingabe.lobby_antwort('MAUS {"x": 300, "y": 300, "text": "Join"}'))
|
|
finally:
|
|
fenster.alle, eingabe._click = alt
|
|
self.assertEqual(geklickt, [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|