def test_process_options_int_min(self): with self.assertRaisesRegexp(TTSError, 'Min is 5'): process_options({'test': { 'type': 'int', 'min': 5 }}, {'test': 3}, TTSError) process_options({'test': {'type': 'int'}}, {'test': 3}, TTSError)
def test_process_options_int_max(self): with self.assertRaisesRegexp(TTSError, 'Max is 8'): process_options({'test': { 'type': 'int', 'max': 8 }}, {'test': 10}, TTSError) process_options({'test': {'type': 'int'}}, {'test': 10}, TTSError)
def test_process_options_enum(self): spec = {'test': {'type': 'enum', 'values': ['one', 'two', 'four']}} with self.assertRaisesRegexp(TTSError, 'Bad test value: None'): process_options(spec, {}, TTSError) with self.assertRaisesRegexp(TTSError, 'Bad test value: three'): process_options(spec, {'test': 'three'}, TTSError) ret = process_options(spec, {'test': 'two'}, TTSError) self.assertEqual(ret, {'test': 'two'})
def __init__(self, **_options): self._logger = logging.getLogger(__name__) self.ioptions = process_options(self.__class__.get_init_options(), _options, TTSError) # Pre-caching potentially slow results self.default_language = 'en' self.languages_options = {} self.default_options = {} self.optionspec = None self.languages = None self.available = self.is_available() if self.available: self.optionspec = self.get_options() self.languages = self.get_languages() self.configure_default()
def test_process_options_int(self): spec = {'test': {'type': 'int', 'min': 5, 'max': 8}} with self.assertRaises(TypeError): process_options(spec, {}, TTSError) ret = process_options(spec, {'test': '6'}, TTSError) self.assertEqual(ret, {'test': 6}) ret = process_options(spec, {'test': '6.2'}, TTSError) self.assertEqual(ret, {'test': 6}) ret = process_options(spec, {'test': 6}, TTSError) self.assertEqual(ret, {'test': 6}) ret = process_options(spec, {'test': 6.1}, TTSError) self.assertEqual(ret, {'test': 6})
def test_process_options_float(self): spec = {'test': {'type': 'float', 'min': 5.2, 'max': 8.9}} with self.assertRaises(TypeError): process_options(spec, {}, TTSError) ret = process_options(spec, {'test': '6'}, TTSError) self.assertEqual(ret, {'test': 6.0}) ret = process_options(spec, {'test': '6.2'}, TTSError) self.assertEqual(ret, {'test': 6.2}) ret = process_options(spec, {'test': 6}, TTSError) self.assertEqual(ret, {'test': 6.0}) ret = process_options(spec, {'test': 6.1}, TTSError) self.assertEqual(ret, {'test': 6.1})
def _configure(self, language=None, voice=None, **_options): self._assert_available() language = language or self.default_language lang_voice, lang_options = self._get_language_options(language) voice = voice or lang_voice if language not in self.languages.keys(): raise TTSError('Bad language: %s' % language, self.languages.keys()) voice = voice if voice else self.languages[language]['default'] if voice not in self.languages[language]['voices'].keys(): raise TTSError('Bad voice: %s' % voice, self.languages[language]['voices'].keys()) voiceinfo = self.languages[language]['voices'][voice] lang_options.update(_options) options = process_options(self.optionspec, lang_options, TTSError) return language, voice, voiceinfo, options
def test_process_options_unknown_param(self): with self.assertRaisesRegexp(TTSError, 'Unknown options'): process_options({}, {'test': 'fail'}, TTSError)
def test_process_options_default_none(self): spec = {'test': {'type': 'str'}} ret = process_options(spec, {}, TTSError) self.assertEqual(ret, {'test': None})
def test_process_options_bad_type(self): with self.assertRaisesRegexp(TTSError, 'Bad type: garbage'): process_options({'test': {'type': 'garbage'}}, {'test': 'fail'}, TTSError)
def test_process_options_bool(self): spec = {'test': {'type': 'bool'}} ret = process_options(spec, {}, TTSError) self.assertEqual(ret, {'test': False}) ret = process_options(spec, {'test': 'yEs'}, TTSError) self.assertEqual(ret, {'test': True})
def test_process_options_default_provided(self): spec = {'test': {'type': 'str', 'default': 'moo'}} ret = process_options(spec, {}, TTSError) self.assertEqual(ret, {'test': 'moo'})
def test_process_options_int_min(self): with self.assertRaisesRegexp(TTSError, 'Min is 5'): process_options({'test': {'type': 'int', 'min': 5}}, {'test': 3}, TTSError) process_options({'test': {'type': 'int'}}, {'test': 3}, TTSError)
def test_process_options_bad_type(self): with self.assertRaisesRegexp(TTSError, 'Bad type: garbage'): process_options({'test': { 'type': 'garbage' }}, {'test': 'fail'}, TTSError)
def test_process_options_int_max(self): with self.assertRaisesRegexp(TTSError, 'Max is 8'): process_options({'test': {'type': 'int', 'max': 8}}, {'test': 10}, TTSError) process_options({'test': {'type': 'int'}}, {'test': 10}, TTSError)