def test_speak(self, tts_factory_mock, config_mock): """Ensure the speech handler executes the tts.""" setup_mocks(config_mock, tts_factory_mock) bus = mock.Mock() speech.init(bus) speak_msg = Message('speak', data={'utterance': 'hello there. world', 'listen': False}, context={'ident': 'a'}) speech.handle_speak(speak_msg) tts_mock.execute.assert_has_calls( [mock.call('hello there.', 'a', False), mock.call('world', 'a', False)])
def test_speak_picroft(self, tts_factory_mock, config_mock): """Ensure that picroft doesn't split the sentence.""" setup_mocks(config_mock, tts_factory_mock) bus = mock.Mock() config_mock.get.return_value = {'enclosure': {'platform': 'picroft'}} speech.init(bus) speak_msg = Message('speak', data={'utterance': 'hello there. world', 'listen': False}, context={'ident': 'a'}) speech.handle_speak(speak_msg) tts_mock.execute.assert_has_calls( [mock.call('hello there. world', 'a', False)]) config_mock.get.return_value = {}
def test_speak_update_tts(self, tts_factory_mock, config_mock): """Verify that a new config triggers reload of tts.""" setup_mocks(config_mock, tts_factory_mock) bus = mock.Mock() config_mock.get.return_value = {'tts': {'module': 'test'}} speech.init(bus) tts_factory_mock.create.reset_mock() speak_msg = Message('speak', data={'utterance': 'hello there. world', 'listen': False}, context={'ident': 'a'}) speech.handle_speak(speak_msg) self.assertFalse(tts_factory_mock.create.called) speech.config = {'tts': {'module': 'test2'}} speech.handle_speak(speak_msg) self.assertTrue(tts_factory_mock.create.called)
def test_speak_errorsound_global_conf(self, tts_factory_mock, config_mock): """Ensure the speech handler executes the error sound instead of the utterance.""" setup_mocks(config_mock, tts_factory_mock) bus = mock.Mock() speech.init(bus) config_mock.get.return_value = {'error_as_sound': True} speak_msg = Message('speak', data={ 'utterance': 'hello there. world', 'listen': False, 'is_error': True }, context={'ident': 'a'}) speech.handle_speak(speak_msg) tts_mock.execute.assert_has_calls( [mock.call('hello there. world', 'a', False, True)])
def test_fallback_tts(self, mimic_cls_mock, tts_factory_mock, config_mock): """Ensure the fallback tts is triggered if the remote times out.""" setup_mocks(config_mock, tts_factory_mock) mimic_mock = mock.Mock() mimic_cls_mock.return_value = mimic_mock tts = tts_factory_mock.create.return_value tts.execute.side_effect = speech.RemoteTTSTimeoutException bus = mock.Mock() speech.init(bus) speak_msg = Message('speak', data={'utterance': 'hello there. world', 'listen': False}, context={'ident': 'a'}) speech.handle_speak(speak_msg) mimic_mock.execute.assert_has_calls( [mock.call('hello there.', 'a', False), mock.call('world', 'a', False)])
def test_abort_speak(self, check_for_signal_mock, tts_factory_mock, config_mock): """Ensure the speech handler aborting speech on stop signal.""" setup_mocks(config_mock, tts_factory_mock) check_for_signal_mock.return_value = True tts = tts_factory_mock.create.return_value def execute_trigger_stop(): speech.handle_stop(None) tts.execute.side_effect = execute_trigger_stop bus = mock.Mock() speech.init(bus) speak_msg = Message('speak', data={'utterance': 'hello there. world', 'listen': False}, context={'ident': 'a'}) speech.handle_speak(speak_msg) self.assertTrue(tts.playback.clear.called)