test_sr_microsoft.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 import ConfigParser
00008 
00009 from nose.tools import raises
00010 from nose.tools import nottest
00011 from rospeex_core.sr.microsoft import Client
00012 from rospeex_core import exceptions as ext
00013 
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 TestSpeechRecognitionClient_Microsoft(unittest.TestCase):
00022     def setUp(self):
00023         base_dir = os.path.dirname(__file__)
00024         filename = os.path.join(base_dir, 'config.cfg')
00025         settings = ConfigParser.ConfigParser()
00026         settings.read(filename)
00027         self.flac_file = os.path.join(
00028             base_dir,
00029             settings.get('SpeechRecognition', 'flac_file')
00030         )
00031         self.broken_wav_file = os.path.join(
00032             base_dir,
00033             settings.get('SpeechRecognition', 'broken_wav_file')
00034         )
00035         self.wav_file = os.path.join(
00036             base_dir,
00037             settings.get('SpeechRecognition', 'wav_file')
00038         )
00039         self.api_key = settings.get(
00040             'SpeechRecognition',
00041             'microsoft_api_key'
00042         )
00043 
00044     @raises(ext.ParameterException)
00045     def test_request_invalid_audio_format_flac(self):
00046         client = Client()
00047         request_data = open(self.flac_file, 'rb').read()
00048         client._api_key = self.api_key
00049         client.request(request_data)
00050 
00051     @raises(ext.ParameterException)
00052     def test_request_invalid_audio_format_broken_wav(self):
00053         language = 'ja'
00054         request_data = open(self.broken_wav_file, 'rb').read()
00055         client = Client()
00056         client._api_key = self.api_key
00057         client.request(data=request_data, language=language)
00058 
00059     @raises(ext.ParameterException)
00060     def test_request_invalid_language(self):
00061         language = 'hoge'
00062         request_data = open(self.wav_file, 'rb').read()
00063         client = Client()
00064         client._api_key = self.api_key
00065         client.request(data=request_data, language=language)
00066 
00067     @raises(ext.ParameterException)
00068     def test_request_invalid_api_key(self):
00069         language = 'ja'
00070         request_data = open(self.wav_file, 'rb').read()
00071         client = Client()
00072         client._api_key = None
00073         client.request(data=request_data, language=language)
00074 
00075     @nottest
00076     @raises(ext.RequestTimeoutException)
00077     def test_request_invalid_request_timeout(self):
00078         language = 'ja'
00079         request_data = open(self.wav_file, 'rb').read()
00080         client = Client()
00081         client._api_key = self.api_key
00082         client.request(data=request_data, language=language, timeout=1)
00083 
00084     @nottest
00085     def test_request_valid_language(self):
00086         for language in Client.LANGUAGES:
00087             request_data = open(self.wav_file, 'rb').read()
00088             client = Client()
00089             client._api_key = self.api_key
00090             msg = client.request(data=request_data, language=language)
00091             logger.info(msg)
00092 
00093 if __name__ == '__main__':
00094     import rosunit
00095     test_class = TestSpeechRecognitionClient_Microsoft
00096     rosunit.unitrun(
00097         'rospeex_core',
00098         'speech_recognition_client_microsoft',
00099         test_class,
00100         None,
00101         coverage_packages=['rospeex_core.sr']
00102     )


rospeex_core
Author(s): Komei Sugiura
autogenerated on Thu Jun 6 2019 18:53:10