00001
00002
00003
00004 import os
00005 import logging
00006 import unittest
00007 from nose.tools import raises
00008 from nose.tools import nottest
00009 import ConfigParser
00010
00011 from rospeex_core import exceptions as ext
00012 from rospeex_core.ss.nict import Client
00013
00014
00015 FORMAT = '[%(levelname)s] %(message)s @%(filename)s:%(funcName)s:%(lineno)d'
00016 logging.basicConfig(format=FORMAT, level=logging.DEBUG)
00017 logger = logging.getLogger(__name__)
00018
00019
00020 class TestNICTClient(unittest.TestCase):
00021 def setUp(self):
00022 base_dir = os.path.dirname(__file__)
00023 settings = ConfigParser.ConfigParser()
00024 filename = os.path.join(base_dir, 'config.cfg')
00025 settings.read(filename)
00026 self.big_text_file = os.path.join(
00027 base_dir,
00028 settings.get('SpeechSynthesis', 'big_text_file')
00029 )
00030
00031 self.big_text_data = None
00032 with open(self.big_text_file, 'r') as f:
00033 self.big_text_data = f.read()
00034
00035 @raises(ext.ParameterException)
00036 def test_request_invalid_message(self):
00037 message = None
00038 language = 'ja'
00039 voice_font = '*'
00040 timeout = 100
00041 client = Client()
00042 client.request(message, language, voice_font, timeout)
00043
00044 @raises(ext.InvalidResponseException)
00045 def test_request_invalid_message_charactor(self):
00046 message = '<'
00047 language = 'ja'
00048 voice_font = '*'
00049 timeout = 100
00050 client = Client()
00051 client.request(message, language, voice_font, timeout)
00052
00053 @raises(ext.UnsupportedLanguageException)
00054 def test_request_invalid_language(self):
00055 message = 'hello'
00056 language = 'de'
00057 voice_font = '*'
00058 timeout = 100
00059 client = Client()
00060 client.request(message, language, voice_font, timeout)
00061
00062 @raises(ext.InvalidRequestException)
00063 def test_request_invalid_url(self):
00064 message = 'hello'
00065 language = 'en'
00066 voice_font = '*'
00067 timeout = 100
00068 client = Client()
00069 client.URL = 'http://rospeex.nict.go.jp/nauth_json/jsServices/hoge'
00070 client.request(message, language, voice_font, timeout)
00071
00072 @raises(ext.ParameterException)
00073 def test_request_invalid_voice_font(self):
00074 message = 'hello'
00075 language = 'ja'
00076 voice_font = 'hogehoge'
00077 timeout = 100
00078 client = Client()
00079 client.request(message, language, voice_font, timeout)
00080
00081 @nottest
00082 @raises(ext.RequestTimeoutException)
00083 def test_request_server_timeout_prev(self):
00084 message = self.big_text_data
00085 language = 'en'
00086 voice_font = '*'
00087 timeout = 1
00088 client = Client()
00089 client.request(message, language, voice_font, timeout)
00090
00091 @nottest
00092 @raises(ext.RequestTimeoutException)
00093 def test_request_server_timeout_post(self):
00094 message = self.big_text_data
00095 language = 'en'
00096 voice_font = '*'
00097 timeout = 2
00098 client = Client()
00099 client.request(message, language, voice_font, timeout)
00100
00101 def test_request_valid_big_message(self):
00102 message = self.big_text_data
00103 language = 'en'
00104 voice_font = '*'
00105 timeout = 100
00106 client = Client()
00107 client.request(message, language, voice_font, timeout)
00108
00109 def test_request_valid_japanese_message(self):
00110 message = u'こんにちは'
00111 language = 'ja'
00112 voice_font = '*'
00113 timeout = 100
00114 client = Client()
00115 client.request(message, language, voice_font, timeout)
00116
00117 def test_request_valid_english_message(self):
00118 message = 'hello everyone.'
00119 language = 'en'
00120 voice_font = '*'
00121 timeout = 100
00122 client = Client()
00123 client.request(message, language, voice_font, timeout)
00124
00125 def test_request_valid_korean_message(self):
00126 message = '안녕하세요'
00127 language = 'ko'
00128 voice_font = '*'
00129 timeout = 100
00130 client = Client()
00131 client.request(message, language, voice_font, timeout)
00132
00133 def test_request_valid_chinese_message(self):
00134 message = '你好'
00135 language = 'zh'
00136 voice_font = '*'
00137 timeout = 100
00138 client = Client()
00139 client.request(message, language, voice_font, timeout)
00140
00141 def test_request_valid_indonesian_message(self):
00142 message = 'Selamat sore'
00143 language = 'id'
00144 voice_font = '*'
00145 timeout = 100
00146 client = Client()
00147 client.request(message, language, voice_font, timeout)
00148
00149 def test_request_valid_myanmar_message(self):
00150 message = 'မင်္ဂလာပါ'
00151 language = 'my'
00152 voice_font = '*'
00153 timeout = 100
00154 client = Client()
00155 client.request(message, language, voice_font, timeout)
00156
00157 def test_request_valid_thai_message(self):
00158 message = 'สวัสดี'
00159 language = 'th'
00160 voice_font = '*'
00161 timeout = 100
00162 client = Client()
00163 client.request(message, language, voice_font, timeout)
00164
00165 def test_request_valid_vietnamese_message(self):
00166 message = 'Xin chào'
00167 language = 'vi'
00168 voice_font = '*'
00169 timeout = 100
00170 client = Client()
00171 client.request(message, language, voice_font, timeout)
00172
00173 if __name__ == '__main__':
00174 import rosunit
00175 test_class = TestNICTClient
00176 rosunit.unitrun(
00177 'rospeex_core',
00178 'speech_synthesis_client_nict',
00179 test_class,
00180 None,
00181 coverage_packages=['rospeex_core.ss']
00182 )