test_ss_nict.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
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 # setup logging
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'        # deutsch
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        # alice in wonder land
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 
00126 if __name__ == '__main__':
00127     import rosunit
00128     test_class = TestNICTClient
00129     rosunit.unitrun(
00130         'rospeex_core',
00131         'speech_synthesis_client_nict',
00132         test_class,
00133         None,
00134         coverage_packages=['rospeex_core.ss']
00135     )


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