48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
|
|
from cthulhu.plugins.nvda2cthulhu import plugin as nvda_plugin
|
|
|
|
|
|
class Nvda2CthulhuRegressionTests(unittest.TestCase):
|
|
def _make_plugin(self):
|
|
plugin = nvda_plugin.Nvda2Cthulhu.__new__(nvda_plugin.Nvda2Cthulhu)
|
|
plugin.interruptEnabled = True
|
|
plugin._dependencies_available = mock.Mock(return_value=True)
|
|
return plugin
|
|
|
|
def test_text_cancel_speech_frame_is_cancel_request(self):
|
|
plugin = self._make_plugin()
|
|
|
|
self.assertEqual(("CancelSpeech", None), plugin._parse_request("CancelSpeech"))
|
|
|
|
def test_websocket_speech_is_queued_instead_of_handled_synchronously(self):
|
|
plugin = self._make_plugin()
|
|
plugin._translation_enabled = mock.Mock(return_value=False)
|
|
|
|
with mock.patch.object(nvda_plugin.speech, "speak") as speak:
|
|
plugin.handle_message("hello")
|
|
|
|
speak.assert_not_called()
|
|
|
|
def test_queued_websocket_speech_runs_on_main_loop(self):
|
|
if not hasattr(nvda_plugin, "GLib"):
|
|
self.fail("nvda2cthulhu does not expose a GLib main-loop dispatcher")
|
|
|
|
plugin = self._make_plugin()
|
|
plugin._translation_enabled = mock.Mock(return_value=False)
|
|
|
|
with mock.patch.object(nvda_plugin.GLib, "idle_add", side_effect=lambda callback, *args: callback(*args)), \
|
|
mock.patch.object(nvda_plugin.speech, "speak") as speak:
|
|
plugin.handle_message("hello")
|
|
|
|
speak.assert_called_once_with("hello", interrupt=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|