Publish the Wine Access protocol on Orca’s service connection and manage helpers per active Wine prefix. Add presentation, dialog capture, documentation, and tests. Preserve the Cthulhu default and shared helper code. Document the single-reader limit and verify Orca cleanup leaves Cthulhu-managed helpers alone. Retain integration artifacts on exceptional failures. Validation: 45 Orca unit tests passed; 11 existing test-environment checks passed; version metadata checks, Python compilation, and staged whitespace checks passed. Full Wine integration and live speech/braille remain unverified here because MinGW, Xvfb, and Orca are unavailable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
"""Dialog message reading through the review protocol."""
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "wine_access"))
|
|
|
|
from review import DialogReader, dialog_text # noqa: E402
|
|
|
|
|
|
def node(role, name="", visible=True, protected=False, ranges=()):
|
|
return {"role": role, "name": name, "visible": visible, "protected": protected,
|
|
"ranges": list(ranges)}
|
|
|
|
|
|
REPLY = {"status": "ok", "nodes": [
|
|
node("window", "Notepad"),
|
|
node("label", ""), # the message box icon
|
|
node("label", "Save changes to\r\n Untitled?"),
|
|
node("push button", "Yes"),
|
|
node("label", "Hidden", visible=False),
|
|
node("label", "secret", protected=True),
|
|
node("label", "Notepad"),
|
|
node("static text", "", ranges=[(0, 4, 0, 4, "More", (0, 0, 1, 1))]),
|
|
]}
|
|
|
|
|
|
class DialogTextTests(unittest.TestCase):
|
|
def test_visible_labels_only_without_title(self):
|
|
self.assertEqual(dialog_text(REPLY, "Notepad"), "Save changes to Untitled? More")
|
|
|
|
def test_failed_capture_has_no_text(self):
|
|
self.assertEqual(dialog_text({"status": "stale", "nodes": REPLY["nodes"]}), "")
|
|
|
|
|
|
class ReaderTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.captures = []
|
|
self.spoken = []
|
|
self.reader = DialogReader(lambda *args: self.captures.append(args),
|
|
lambda text, window: self.spoken.append((text, window)))
|
|
self.assertTrue(self.reader.register(":1.5", "/review", 1))
|
|
|
|
def focus(self, window="w1", role="dialog", sender=":1.5"):
|
|
return self.reader.focus(sender, window, "f", 3, "Notepad", role)
|
|
|
|
def test_dialog_captured_once_and_spoken(self):
|
|
self.assertTrue(self.focus())
|
|
self.assertTrue(self.focus())
|
|
self.assertEqual(len(self.captures), 1)
|
|
self.assertEqual(self.captures[0][:5], (":1.5", "/review", "w1", "f", 3))
|
|
self.captures[0][5](REPLY)
|
|
self.assertEqual(self.spoken, [("Save changes to Untitled? More", "Notepad")])
|
|
|
|
def test_plain_windows_are_not_captured(self):
|
|
self.focus(role="window")
|
|
self.assertEqual(self.captures, [])
|
|
|
|
def test_failed_capture_retries_on_next_focus(self):
|
|
self.focus()
|
|
self.captures[0][5](None)
|
|
self.focus()
|
|
self.assertEqual(len(self.captures), 2)
|
|
|
|
def test_leaving_dialog_drops_late_reply_and_allows_reread(self):
|
|
self.focus()
|
|
self.focus(window="main", role="window")
|
|
self.captures[0][5](REPLY)
|
|
self.assertEqual(self.spoken, [])
|
|
self.focus()
|
|
self.assertEqual(len(self.captures), 2)
|
|
|
|
def test_unregistered_sender_and_old_version_rejected(self):
|
|
self.assertFalse(self.focus(sender=":1.9"))
|
|
self.assertFalse(self.reader.register(":1.6", "/review", 0))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|