Changed how speech interruptions are handled hopefully improved things being interrupted when they shouldn't be.
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
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 import settings
|
||||
from cthulhu import speech
|
||||
from cthulhu import cthulhu_state
|
||||
from cthulhu.scripts import default
|
||||
|
||||
|
||||
class SpeechDefaultPolicyRegressionTests(unittest.TestCase):
|
||||
def _make_settings_manager(self):
|
||||
values = {
|
||||
"enableSpeech": True,
|
||||
"onlySpeakDisplayedText": False,
|
||||
"messagesAreDetailed": True,
|
||||
"enableBraille": False,
|
||||
"enableBrailleMonitor": False,
|
||||
"enableFlashMessages": False,
|
||||
"voices": {settings.SYSTEM_VOICE: "system"},
|
||||
"capitalizationStyle": settings.CAPITALIZATION_STYLE_NONE,
|
||||
"verbalizePunctuationStyle": settings.PUNCTUATION_STYLE_NONE,
|
||||
}
|
||||
|
||||
manager = mock.Mock()
|
||||
manager.getSetting.side_effect = values.get
|
||||
return manager
|
||||
|
||||
def _make_script(self):
|
||||
testScript = default.Script.__new__(default.Script)
|
||||
testScript.speechAndVerbosityManager = mock.Mock()
|
||||
return testScript
|
||||
|
||||
def test_speech_speak_queues_by_default(self):
|
||||
server = mock.Mock()
|
||||
|
||||
with (
|
||||
mock.patch.object(speech, "_speechserver", server),
|
||||
mock.patch.object(speech, "_write_to_monitor"),
|
||||
mock.patch.object(speech.speech_history, "add"),
|
||||
mock.patch.object(cthulhu_state, "activeScript", None),
|
||||
):
|
||||
speech.speak("status")
|
||||
|
||||
server.speak.assert_called_once()
|
||||
self.assertFalse(server.speak.call_args.args[2])
|
||||
|
||||
def test_speech_speak_explicit_interrupt_is_preserved(self):
|
||||
server = mock.Mock()
|
||||
|
||||
with (
|
||||
mock.patch.object(speech, "_speechserver", server),
|
||||
mock.patch.object(speech, "_write_to_monitor"),
|
||||
mock.patch.object(speech.speech_history, "add"),
|
||||
mock.patch.object(cthulhu_state, "activeScript", None),
|
||||
):
|
||||
speech.speak("status", interrupt=True)
|
||||
|
||||
server.speak.assert_called_once()
|
||||
self.assertTrue(server.speak.call_args.args[2])
|
||||
|
||||
def test_present_message_queues_by_default(self):
|
||||
testScript = self._make_script()
|
||||
manager = self._make_settings_manager()
|
||||
|
||||
with (
|
||||
mock.patch.object(default.cthulhu.cthulhuApp, "settingsManager", manager),
|
||||
mock.patch.object(default.speech, "speak") as speak,
|
||||
):
|
||||
default.Script.presentMessage(testScript, "Status")
|
||||
|
||||
speak.assert_called_once_with("Status", "system", False)
|
||||
|
||||
def test_present_message_explicit_interrupt_is_preserved(self):
|
||||
testScript = self._make_script()
|
||||
manager = self._make_settings_manager()
|
||||
|
||||
with (
|
||||
mock.patch.object(default.cthulhu.cthulhuApp, "settingsManager", manager),
|
||||
mock.patch.object(default.speech, "speak") as speak,
|
||||
):
|
||||
default.Script.presentMessage(testScript, "Status", interrupt=True)
|
||||
|
||||
speak.assert_called_once_with("Status", "system", True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -30,6 +30,14 @@ class SpeechDispatcherInterruptRegressionTests(unittest.TestCase):
|
||||
server._cancel.assert_called_once_with()
|
||||
server._speak.assert_called_once_with("long utterance", None)
|
||||
|
||||
def test_string_speech_queues_by_default(self):
|
||||
server = self._make_server()
|
||||
|
||||
server.speak("next")
|
||||
|
||||
server._cancel.assert_not_called()
|
||||
server._speak.assert_called_once_with("next", None)
|
||||
|
||||
def test_recent_key_echo_suppresses_backend_cancel(self):
|
||||
server = self._make_server()
|
||||
server._lastKeyEchoTime = time.time()
|
||||
|
||||
@@ -38,8 +38,7 @@ class StructuralNavigationTableRegressionTests(unittest.TestCase):
|
||||
|
||||
navigator._presentObject.assert_called_once_with("cell", 0)
|
||||
navigator._script.presentMessage.assert_called_once_with(
|
||||
messages.TABLE_CELL_COORDINATES % {"row": 2, "column": 3},
|
||||
interrupt=False,
|
||||
messages.TABLE_CELL_COORDINATES % {"row": 2, "column": 3}
|
||||
)
|
||||
|
||||
def test_wrapping_announcement_does_not_interrupt_wrapped_object(self):
|
||||
@@ -78,7 +77,7 @@ class StructuralNavigationTableRegressionTests(unittest.TestCase):
|
||||
events,
|
||||
[
|
||||
("present", first, "arg"),
|
||||
("message", messages.WRAPPING_TO_TOP, {"interrupt": False}),
|
||||
("message", messages.WRAPPING_TO_TOP, {}),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ class WebPresentationModeSpeechRegressionTests(unittest.TestCase):
|
||||
):
|
||||
web_script.Script.togglePresentationMode(testScript, None, "document")
|
||||
|
||||
testScript.presentMessage.assert_called_once_with(messages.MODE_BROWSE, interrupt=False)
|
||||
testScript.presentMessage.assert_called_once_with(messages.MODE_BROWSE)
|
||||
soundManager.playBrowseModeSound.assert_called_once_with()
|
||||
self.assertFalse(testScript._inFocusMode)
|
||||
self.assertFalse(testScript._focusModeIsSticky)
|
||||
@@ -200,7 +200,7 @@ class WebPresentationModeSpeechRegressionTests(unittest.TestCase):
|
||||
):
|
||||
web_script.Script.togglePresentationMode(testScript, None, "document")
|
||||
|
||||
testScript.presentMessage.assert_called_once_with(messages.MODE_FOCUS, interrupt=False)
|
||||
testScript.presentMessage.assert_called_once_with(messages.MODE_FOCUS)
|
||||
soundManager.playFocusModeSound.assert_called_once_with()
|
||||
self.assertTrue(testScript._inFocusMode)
|
||||
self.assertFalse(testScript._focusModeIsSticky)
|
||||
@@ -311,7 +311,7 @@ class WebDescriptionChangeRegressionTests(unittest.TestCase):
|
||||
result = web_script.Script.onDescriptionChanged(testScript, event)
|
||||
|
||||
self.assertTrue(result)
|
||||
testScript.presentMessage.assert_called_once_with("Helpful tooltip", interrupt=False)
|
||||
testScript.presentMessage.assert_called_once_with("Helpful tooltip")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -378,7 +378,7 @@ class WebSelectionRegressionTests(unittest.TestCase):
|
||||
testScript.utilities.setCaretContext.assert_called_once_with(section, 1, document)
|
||||
setLocusOfFocus.assert_called_once_with(event, section, False, True)
|
||||
testScript.speakContents.assert_called_once_with([[section, 0, 1, "D"]])
|
||||
testScript.speakMessage.assert_called_once_with(messages.TEXT_SELECTED, interrupt=False)
|
||||
testScript.speakMessage.assert_called_once_with(messages.TEXT_SELECTED)
|
||||
self.assertEqual(
|
||||
testScript.pointOfReference["syntheticWebSelection"]["string"],
|
||||
"D",
|
||||
@@ -414,7 +414,7 @@ class WebSelectionRegressionTests(unittest.TestCase):
|
||||
testScript.utilities.setCaretContext.assert_called_once_with(link, 0, document)
|
||||
setLocusOfFocus.assert_called_once_with(event, link, False, True)
|
||||
testScript.speakContents.assert_called_once_with([[link, 0, 1, "S"]])
|
||||
testScript.speakMessage.assert_called_once_with(messages.TEXT_SELECTED, interrupt=False)
|
||||
testScript.speakMessage.assert_called_once_with(messages.TEXT_SELECTED)
|
||||
self.assertEqual(
|
||||
testScript.pointOfReference["syntheticWebSelection"]["string"],
|
||||
"S",
|
||||
|
||||
Reference in New Issue
Block a user