Go to the documentation of this file.00001
00002
00003
00004 PKG_NAME = 'rospeex_core'
00005
00006 try:
00007 import roslib; roslib.load_manifest(PKG_NAME)
00008 except:
00009 pass
00010
00011 import os
00012 import logging
00013 import unittest
00014 from nose.tools import eq_, raises
00015 import ConfigParser
00016
00017 from rospeex_core.ss.client_nict import SpeechSynthesisClient_NICT
00018 from rospeex_core.exceptions import ParameterException
00019 from rospeex_core.exceptions import InvalidResponseException
00020 from rospeex_core.exceptions import InvalidRequestException
00021 from rospeex_core.exceptions import RequestTimeoutException
00022 from rospeex_core.exceptions import SpeechSynthesisException
00023 from rospeex_core.exceptions import UnsupportedLanguageException
00024
00025
00026 logger = logging.getLogger(__name__)
00027 logger.setLevel(logging.DEBUG)
00028 formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(filename)s:%(lineno)d:%(message)s')
00029 ch = logging.StreamHandler()
00030 ch.setFormatter(formatter)
00031 logger.addHandler(ch)
00032
00033
00034 class TestSpeechSynthesisClient_NICT(unittest.TestCase):
00035 def setUp(self):
00036 base_dir = os.path.dirname(__file__)
00037 settings = ConfigParser.ConfigParser()
00038 filename = os.path.join(base_dir, 'config.cfg')
00039 settings.read(filename)
00040 self.big_text_file = os.path.join(base_dir, settings.get('SpeechSynthesis', 'big_text_file'))
00041
00042 self.big_text_data = None
00043 with open(self.big_text_file, 'r') as f:
00044 self.big_text_data = f.read()
00045
00046
00047 @raises(ParameterException)
00048 def test_request_invalid_message(self):
00049 message = None
00050 language = 'ja'
00051 voice_font = '*'
00052 timeout = 100
00053 client = SpeechSynthesisClient_NICT()
00054 client.request(message, language, voice_font, timeout)
00055
00056
00057 @raises(InvalidResponseException)
00058 def test_request_invalid_message_charactor(self):
00059 message = '<'
00060 language = 'ja'
00061 voice_font = '*'
00062 timeout = 100
00063 client = SpeechSynthesisClient_NICT()
00064 client.request(message, language, voice_font, timeout)
00065
00066
00067 @raises(UnsupportedLanguageException)
00068 def test_request_invalid_language(self):
00069 message = 'hello'
00070 language = 'de'
00071 voice_font = '*'
00072 timeout = 100
00073 client = SpeechSynthesisClient_NICT()
00074 client.request(message, language, voice_font, timeout)
00075
00076
00077 @raises(InvalidRequestException)
00078 def test_request_invalid_url(self):
00079 message = 'hello'
00080 language = 'en'
00081 voice_font = '*'
00082 timeout = 100
00083 client = SpeechSynthesisClient_NICT()
00084 client.URL = 'http://rospeex.ucri.jgn-x.jp/nauth_json/jsServices/hoge'
00085 client.request(message, language, voice_font, timeout)
00086
00087
00088 @raises(ParameterException)
00089 def test_request_invalid_voice_font(self):
00090 message = 'hello'
00091 language = 'ja'
00092 voice_font = 'hogehoge'
00093 timeout = 100
00094 client = SpeechSynthesisClient_NICT()
00095 client.request(message, language, voice_font, timeout)
00096
00097
00098 @raises(RequestTimeoutException)
00099 def test_request_server_timeout_prev(self):
00100 message = self.big_text_data
00101 language = 'en'
00102 voice_font = '*'
00103 timeout = 1
00104 client = SpeechSynthesisClient_NICT()
00105 client.request(message, language, voice_font, timeout)
00106
00107
00108 @raises(RequestTimeoutException)
00109 def test_request_server_timeout_post(self):
00110 message = self.big_text_data
00111 language = 'en'
00112 voice_font = '*'
00113 timeout = 2
00114 client = SpeechSynthesisClient_NICT()
00115 client.request(message, language, voice_font, timeout)
00116
00117
00118 def test_request_valid_big_message(self):
00119 message = self.big_text_data
00120 language = 'en'
00121 voice_font = '*'
00122 timeout = 100
00123 client = SpeechSynthesisClient_NICT()
00124 client.request(message, language, voice_font, timeout)
00125
00126
00127 def test_request_valid_japanese_message(self):
00128 message = u'こんにちは'
00129 language = 'ja'
00130 voice_font = '*'
00131 timeout = 100
00132 client = SpeechSynthesisClient_NICT()
00133 client.request(message, language, voice_font, timeout)
00134
00135
00136 def test_request_valid_english_message(self):
00137 message = 'hello everyone.'
00138 language = 'en'
00139 voice_font = '*'
00140 timeout = 100
00141 client = SpeechSynthesisClient_NICT()
00142 client.request(message, language, voice_font, timeout)
00143
00144
00145 if __name__ == '__main__':
00146 import rosunit
00147 test_class = TestSpeechSynthesisClient_NICT
00148 rosunit.unitrun(PKG_NAME, 'speech_synthesis_client_nict', test_class, None, coverage_packages=['rospeex.ss'])