16 from __future__
import print_function
18 from mock
import patch, MagicMock
25 """important: import tts which is a relay package:: 27 devel/lib/python2.7/dist-packages/ 32 per http://docs.ros.org/api/catkin/html/user_guide/setup_dot_py.html: 34 A relay package is a folder with an __init__.py folder and nothing else. 35 Importing this folder in python will execute the contents of __init__.py, 36 which will in turn import the original python modules in the folder in 37 the sourcespace using the python exec() function. 40 self.assertIsNotNone(tts)
44 speech_synthesizer = SpeechSynthesizer()
45 self.assertEqual(
'text', speech_synthesizer.default_text_type)
47 @patch(
'tts.amazonpolly.AmazonPolly')
49 polly_obj_mock = MagicMock()
50 polly_class_mock.return_value = polly_obj_mock
55 "output_path": "/tmp/test" 58 expected_polly_synthesize_args = {
59 'output_format':
'ogg_vorbis',
61 'sample_rate':
'22050',
64 'output_path':
"/tmp/test" 68 from tts.srv
import SynthesizerRequest
69 speech_synthesizer = SpeechSynthesizer(engine=
'POLLY_LIBRARY')
70 request = SynthesizerRequest(text=test_text, metadata=test_metadata)
71 response = speech_synthesizer._node_request_handler(request)
73 self.assertGreater(polly_class_mock.call_count, 0)
74 polly_obj_mock.synthesize.assert_called_with(**expected_polly_synthesize_args)
76 self.assertEqual(response.result, polly_obj_mock.synthesize.return_value.result)
78 @patch(
'tts.amazonpolly.AmazonPolly')
80 polly_obj_mock = MagicMock()
81 polly_class_mock.return_value = polly_obj_mock
84 test_metadata =
'''I am no JSON''' 87 from tts.srv
import SynthesizerRequest
88 speech_synthesizer = SpeechSynthesizer(engine=
'POLLY_LIBRARY')
89 request = SynthesizerRequest(text=test_text, metadata=test_metadata)
90 response = speech_synthesizer._node_request_handler(request)
92 self.assertTrue(response.result.startswith(
'Exception: '))
94 @patch(
'tts.amazonpolly.AmazonPolly')
96 polly_obj_mock = MagicMock()
97 polly_class_mock.return_value = polly_obj_mock
103 SpeechSynthesizer(engine=
'NON-EXIST ENGINE')
104 except Exception
as e:
107 self.assertTrue(isinstance(ex, SpeechSynthesizer.BadEngineError))
111 source_file_dir = os.path.dirname(os.path.abspath(__file__))
112 synthersizer_path = os.path.join(source_file_dir,
'..',
'scripts',
'synthesizer_node.py')
114 o = subprocess.check_output([
'python', synthersizer_path,
'-h'])
115 self.assertTrue(str(o).startswith(
'Usage: '))
117 @patch(
'tts.synthesizer.SpeechSynthesizer')
120 with patch.object(sys,
'argv', [
'synthesizer_node.py']):
123 speech_synthesizer_class_mock.assert_called_with(engine=
'POLLY_SERVICE', polly_service_name=
'polly')
124 speech_synthesizer_class_mock.return_value.start.assert_called_with(node_name=
'synthesizer_node',
125 service_name=
'synthesizer')
127 @patch(
'tts.synthesizer.SpeechSynthesizer')
130 with patch.object(sys,
'argv', [
'synthesizer_node.py',
'-e',
'POLLY_LIBRARY']):
131 from tts
import synthesizer
133 speech_synthesizer_class_mock.assert_called_with(engine=
'POLLY_LIBRARY')
134 self.assertGreater(speech_synthesizer_class_mock.return_value.start.call_count, 0)
136 @patch(
'tts.synthesizer.SpeechSynthesizer')
139 with patch.object(sys,
'argv', [
'synthesizer_node.py',
'-p',
'apolly']):
140 from tts
import synthesizer
142 speech_synthesizer_class_mock.assert_called_with(engine=
'POLLY_SERVICE', polly_service_name=
'apolly')
143 self.assertGreater(speech_synthesizer_class_mock.return_value.start.call_count, 0)
146 if __name__ ==
'__main__':
148 rosunit.unitrun(
'tts',
'unittest-synthesizer', TestSynthesizer)
def test_cli_engine_dispatching_1(self, speech_synthesizer_class_mock)
def test_good_synthesis_with_mostly_default_args_using_polly_lib(self, polly_class_mock)
def test_cli_engine_dispatching_3(self, speech_synthesizer_class_mock)
def test_bad_engine(self, polly_class_mock)
def test_cli_help_message(self)
def test_synthesis_with_bad_metadata_using_polly_lib(self, polly_class_mock)
def test_cli_engine_dispatching_2(self, speech_synthesizer_class_mock)