test_ss_google.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 # import python libraries
00005 import os
00006 import logging
00007 import unittest
00008 from nose.tools import raises
00009 from nose.tools import nottest
00010 import ConfigParser
00011 
00012 from rospeex_core import exceptions as ext
00013 from rospeex_core.ss.google import Client
00014 
00015 # setup logging
00016 FORMAT = '[%(levelname)s] %(message)s @%(filename)s:%(funcName)s:%(lineno)d'
00017 logging.basicConfig(format=FORMAT, level=logging.DEBUG)
00018 logger = logging.getLogger(__name__)
00019 
00020 
00021 class TestGoogleClient(unittest.TestCase):
00022     def setUp(self):
00023         base_dir = os.path.dirname(__file__)
00024         settings = ConfigParser.ConfigParser()
00025         filename = os.path.join(base_dir, 'config.cfg')
00026         settings.read(filename)
00027         self.big_text_file = os.path.join(
00028             base_dir,
00029             settings.get('SpeechSynthesis', 'big_text_for_google_file')
00030         )
00031 
00032         self.big_text_data = None
00033         with open(self.big_text_file, 'r') as f:
00034             self.big_text_data = f.read()
00035 
00036     @raises(ext.ParameterException)
00037     def test_request_invalid_message(self):
00038         message = None
00039         language = 'ja'
00040         voice_font = '*'
00041         timeout = 100
00042         client = Client()
00043         client.request(message, language, voice_font, timeout)
00044 
00045     @raises(ext.UnsupportedLanguageException)
00046     def test_request_invalid_language(self):
00047         message = 'hello'
00048         language = 'de'        # deutsch
00049         voice_font = '*'
00050         timeout = 100
00051         client = Client()
00052         client.request(message, language, voice_font, timeout)
00053 
00054     @raises(ext.InvalidRequestException)
00055     def test_request_invalid_url(self):
00056         message = 'hello'
00057         language = 'en'
00058         voice_font = '*'
00059         timeout = 100
00060         client = Client()
00061         client.URL = 'http://translate.google.com/translate_tts2?'
00062         client.request(message, language, voice_font, timeout)
00063 
00064     @nottest
00065     @raises(ext.SpeechSynthesisException)
00066     def test_request_invalid_voice_font(self):
00067         message = 'hello'
00068         language = 'ja'
00069         voice_font = 'hogehoge'
00070         timeout = 100
00071         client = Client()
00072         client.request(message, language, voice_font, timeout)
00073 
00074     @nottest
00075     @raises(ext.RequestTimeoutException)
00076     def test_request_server_timeout_prev(self):
00077         message = self.big_text_data
00078         language = 'en'
00079         voice_font = '*'
00080         timeout = 1
00081         client = Client()
00082         client.request(message, language, voice_font, timeout)
00083 
00084     @nottest
00085     @raises(ext.RequestTimeoutException)
00086     def test_request_server_timeout_post(self):
00087         message = self.big_text_data
00088         language = 'en'
00089         voice_font = '*'
00090         timeout = 2
00091         client = Client()
00092         client.request(message, language, voice_font, timeout)
00093 
00094     @nottest
00095     def test_request_valid_big_message(self):
00096         message = self.big_text_data        # alice in wonder land
00097         language = 'en'
00098         voice_font = '*'
00099         timeout = 100
00100         client = Client()
00101         client.request(message, language, voice_font, timeout)
00102 
00103     @nottest
00104     def test_request_valid_japanese_message(self):
00105         message = u'こんにちは'
00106         language = 'ja'
00107         voice_font = '*'
00108         timeout = 100
00109         client = Client()
00110         client.request(message, language, voice_font, timeout)
00111 
00112     @nottest
00113     def test_request_valid_english_message(self):
00114         message = 'hello everyone.'
00115         language = 'en'
00116         voice_font = '*'
00117         timeout = 100
00118         client = Client()
00119         client.request(message, language, voice_font, timeout)
00120 
00121 
00122 if __name__ == '__main__':
00123     import rosunit
00124     test_class = TestGoogleClient
00125     rosunit.unitrun(
00126         'rospeex_core',
00127         'speech_synthesis_client_google',
00128         test_class,
00129         None,
00130         coverage_packages=['rospeex_core.ss']
00131     )


rospeex_core
Author(s): Komei Sugiura
autogenerated on Thu Apr 20 2017 03:08:53