feat: merge AT-SPI targeting and delay post-action screenshots
This commit is contained in:
+32
-1
@@ -1,9 +1,14 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
import sys
|
||||
sys.path.insert(0, str(Path(__file__).parents[1] / "vm"))
|
||||
import tempfile
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import patch, Mock
|
||||
from types import SimpleNamespace
|
||||
from contextlib import ExitStack
|
||||
import io
|
||||
|
||||
spec = importlib.util.spec_from_file_location("desktop", Path(__file__).parents[1] / "vm/desktop.py")
|
||||
desktop = importlib.util.module_from_spec(spec)
|
||||
@@ -11,6 +16,32 @@ spec.loader.exec_module(desktop)
|
||||
|
||||
|
||||
class ValidationTests(unittest.TestCase):
|
||||
def test_settling_delay_precedes_final_capture_only_after_actions(self):
|
||||
for actions in ([], [{"type": "click", "x": 500, "y": 500}]):
|
||||
events = []
|
||||
image = Mock(size=(1280, 800), width=1280, height=800)
|
||||
def grab(**kwargs):
|
||||
events.append("capture")
|
||||
return image
|
||||
with tempfile.TemporaryDirectory() as directory, ExitStack() as stack:
|
||||
state = Path(directory)
|
||||
(state / "session.json").write_text('{"DISPLAY": ":0"}')
|
||||
stack.enter_context(patch.object(desktop, "STATE", state))
|
||||
stack.enter_context(patch.object(sys, "argv", ["desktop.py"]))
|
||||
stack.enter_context(patch.object(sys, "stdin", io.StringIO(json.dumps({"actions": actions, "coordinateSpace": "normalized_1000"}))))
|
||||
stack.enter_context(patch.object(sys, "stdout", io.StringIO()))
|
||||
stack.enter_context(patch.dict(sys.modules, {"PIL": SimpleNamespace(ImageGrab=SimpleNamespace(grab=grab))}))
|
||||
stack.enter_context(patch("time.sleep", side_effect=lambda seconds: events.append(seconds)))
|
||||
command = stack.enter_context(patch.object(desktop, "run", side_effect=lambda *args: events.append("action")))
|
||||
stack.enter_context(patch.object(desktop.accessibility, "collect", return_value={"targets": [], "warning": None}))
|
||||
stack.enter_context(patch.object(desktop.accessibility, "annotate", return_value=image))
|
||||
desktop.main()
|
||||
if actions:
|
||||
self.assertEqual(events, ["capture", "action", 0.5, "capture"])
|
||||
command.assert_called_once_with("xdotool", "mousemove", "--sync", "640", "400", "click", "1")
|
||||
else:
|
||||
self.assertEqual(events, ["capture", "capture"])
|
||||
|
||||
def test_session_save(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
state = Path(directory)
|
||||
|
||||
Reference in New Issue
Block a user