Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
titilambert committed Sep 13, 2016
1 parent 2de6c33 commit b58d217
Show file tree
Hide file tree
Showing 22 changed files with 297 additions and 29 deletions.
5 changes: 4 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[run]
concurrency = multiprocessing
include =
tuxeatpi/*
*/tuxeatpi/*
omit =
*/tuxeatpi/tests/*

17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ set-locales:
sudo sed -i 's/# \(fr_CA.UTF-8 .*\)/\1/g' /etc/locale.gen
sudo locale-gen

hotword: hotword-en hotword-fr

hotword-fr:
# Get acoustic model fr
mkdir -p pocketsphinx-data/fra-FRA/
Expand All @@ -77,10 +79,17 @@ hotword-clean:
### Test targets
#######################################

test-run:
test-run: test-syntax test-unit

test-syntax:
rm -rf .coverage cover/
pep8 --max-line-length=100 --exclude='*.pyc' --exclude=tuxeatpi/experimental tuxeatpi
pylint --rcfile=.pylintrc -r no tuxeatpi
env/bin/coverage run --include='*/tuxeatpi/*' --omit='*/tuxeatpi/tests/*' `which nosetests` --with-html --with-xunit tuxeatpi tests -svd
env/bin/coverage combine
env/bin/coverage report

test-unit:
rm -rf .coverage nosetest.xml nosetests.html htmlcov
#env/bin/coverage run --include='*/tuxeatpi/*' --omit='*/tuxeatpi/tests/*' `which nosetests` --with-html --with-xunit tuxeatpi tests -svd
nosetests --with-coverage --cover-erase --cover-package=tuxeatpi --with-html --with-xunit tuxeatpi tests -svd
coverage combine
coverage html
#coverage report
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'tuxeatpi.nlu',
'tuxeatpi.actionner',
'tuxeatpi.actions',
'tuxeatpi.hotword',
'tuxeatpi.components',
'tuxeatpi.fake_components',
]
Expand Down
34 changes: 34 additions & 0 deletions tests/actionner/actionner_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from io import StringIO
from multiprocessing import Queue
import logging
import sys
import time
import unittest

from tuxeatpi.actionner.actionner import Actionner
from tuxeatpi.tux import Tux
from tuxeatpi.libs.settings import Settings


class ActionnerTests(unittest.TestCase):

def test_actionner(self):
"""Basic Actionner Tests"""
logger = logging.getLogger(name="TestLogger")
conf_file = "tests/actionner/conf/actionner_tests_conf_1.yaml"
mytux = Tux(conf_file)
# Get actionner object
actionner = mytux.actionner
# Test mute functions
# self.assertEqual(voice.is_mute(), False, "Bad mute state")
# voice.mute()
# self.assertEqual(voice.is_mute(), True, "Bad mute state")
# voice.unmute()
# self.assertEqual(voice.is_mute(), False, "Bad mute state")
# Test speaking
# self.assertEqual(voice.is_speaking(), False, "Bad speaking state")
# Test tts
mytux.actionner._say("hello world")
time.sleep(2)
# self.assertRaises(RuntimeError, lambda: tts_queue.put("hello world"))
mytux.shutdown()
23 changes: 23 additions & 0 deletions tests/actionner/conf/actionner_tests_conf_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
tux:
advanced:
fake: true
log_level: DEBUG
data:
birthday: 1473716045.0199971
global:
gender: male
name: TuxDroid
pins:
wings:
left_switch: 17
movement: 22
position: 25
right_switch: 4
speech:
app_id: FAKE_APP_ID
app_key: FA1EA331E666
codec: wav
hotword: hello
language: eng-USA
url: https://ws.dev.nuance.com
voice: tom
Empty file added tests/nlu/__init__.py
Empty file.
122 changes: 122 additions & 0 deletions tests/nlu/text_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from io import StringIO
from multiprocessing import Queue
import logging
import sys
import time
import unittest

from tuxeatpi.actionner.actionner import Actionner
from tuxeatpi.tux import Tux
from tuxeatpi.libs.settings import Settings
from tuxeatpi.nlu.text import NLUText


from unittest.mock import MagicMock, Mock, patch


def toto():
print("QQQQEEEEEEEEEEEEEEEE")
sys.modules['get_event_loop'] = toto
#from tuxeatpi.nlu.common import WebsocketConnection, NLUBase, get_event_loop

import threading
import aiohttp
import asyncio
class MyLoop1(asyncio.AbstractEventLoop):
def run_until_complete(self, *args, **kwargs):
return {'nlu_interpretation_results': {'payload': {'interpretations': [{'literal': 'What is your name', 'action': {'intent': {'value': 'tux__get_name', 'confidence': 1.0}}}]}}}


class MyLoop2(asyncio.AbstractEventLoop):
def run_until_complete(self, *args, **kwargs):
return {'nlu_interpretation_results': {'payload': {'interpretations': [{'literal': 'What is your name', 'action': {'intent': {'value': 'tux__get_name', 'confidence': 0.7}}}]}}}


class MyLoop3(asyncio.AbstractEventLoop):
def run_until_complete(self, *args, **kwargs):
return {'nlu_interpretation_results': {'payload': {'interpretations': [{'literal': 'What is your name', 'action': {'intent': {'value': 'NO_MATCH', 'confidence': 1.0}}}]}}}


class MyLoop4(asyncio.AbstractEventLoop):
def run_until_complete(self, *args, **kwargs):
return {'nlu_interpretation_results': {'payload': {'interpretations': [{'literal': 'What is your name', 'action': {'intent': {'value': 'badintent', 'confidence': 1.0}}}]}}}


class NLUTextTests(unittest.TestCase):
myloop1 = MyLoop1()
myloop2 = MyLoop2()
myloop3 = MyLoop3()
myloop4 = MyLoop4()

@patch('asyncio.get_event_loop', MagicMock(return_value=myloop1))
def test_nlutext_1_0(self):
"""NLU text with 1.0 confidence Tests"""
logger = logging.getLogger(name="TestLogger")
conf_file = "tests/tux/conf/tux_tests_conf_1.yaml"
settings = Settings(conf_file, logger)
# Get actionner object
action_queue = Queue()
nlu_queue = Queue()
tts_queue = Queue()
nlu_text = NLUText(settings, action_queue, nlu_queue, tts_queue, logger)
t = threading.Timer(4, nlu_text.stop, [])
t.start()
t = threading.Timer(2, nlu_queue.put, [(False, "What is your name ?")])
t.start()
nlu_text.run()

@patch('asyncio.get_event_loop', MagicMock(return_value=myloop2))
def test_nlutext_0_7(self):
"""NLU text with 0.7 confidence Tests"""
logger = logging.getLogger(name="TestLogger")
conf_file = "tests/tux/conf/tux_tests_conf_1.yaml"
settings = Settings(conf_file, logger)
# Get actionner object
action_queue = Queue()
nlu_queue = Queue()
tts_queue = Queue()
nlu_text = NLUText(settings, action_queue, nlu_queue, tts_queue, logger)
t = threading.Timer(4, nlu_text.stop, [])
t.start()
t = threading.Timer(2, nlu_queue.put, [(False, "What is your name ?")])
t.start()
nlu_text.run()


@patch('asyncio.get_event_loop', MagicMock(return_value=myloop3))
def test_nlutext_nomatch(self):
"""NLU text with nomatch confidence Tests"""
logger = logging.getLogger(name="TestLogger")
conf_file = "tests/tux/conf/tux_tests_conf_1.yaml"
settings = Settings(conf_file, logger)
# Get actionner object
action_queue = Queue()
nlu_queue = Queue()
tts_queue = Queue()
nlu_text = NLUText(settings, action_queue, nlu_queue, tts_queue, logger)
t = threading.Timer(4, nlu_text.stop, [])
t.start()
t = threading.Timer(2, nlu_queue.put, [(False, "What is your name ?")])
t.start()
nlu_text.run()


@patch('asyncio.get_event_loop', MagicMock(return_value=myloop4))
def test_nlutext_badintent (self):
"""NLU text with badintent Tests"""
logger = logging.getLogger(name="TestLogger")
conf_file = "tests/tux/conf/tux_tests_conf_1.yaml"
settings = Settings(conf_file, logger)
# Get actionner object
action_queue = Queue()
nlu_queue = Queue()
tts_queue = Queue()
nlu_text = NLUText(settings, action_queue, nlu_queue, tts_queue, logger)
t = threading.Timer(4, nlu_text.stop, [])
t.start()
t = threading.Timer(2, nlu_queue.put, [(False, "What is your name ?")])
t.start()
nlu_text.run()


# return {'message': 'query_response', 'transaction_id': 123, 'NMAS_PRFX_TRANSACTION_ID': '123', 'final_response': 1, 'result_type': 'NDSP_APP_CMD', 'result_format': 'nlu_interpretation_results', 'nlu_interpretation_results': {'status': 'success', 'final_response': 1, 'payload_version': '1.0', 'payload_format': 'nlu-base', 'payload': {'interpretations': [{'literal': 'Quel est ton nom', 'action': {'intent': {'value': 'tux__get_name', 'confidence': 1.0}}}], 'type': 'nlu-1.0', 'diagnostic_info': {'nlps_profile_package': 'QUICKNLU', 'adk_dialog_manager_status': 'undefined', 'nlps_profile': 'QUICKNLUDYN', 'third_party_delay': '0', 'ext_map_time': '0', 'nlps_profile_package_version': 'nlps(z):6.2.200.13.1-B258', 'nlu_annotator': 'com.nuance.QUICKNLU.quicknlu.Client', 'fieldId': 'dm_main', 'int_map_time': '0', 'context_tag': 'master', 'nlps_version': 'nlps(z):6.2.200.13.1-B258;Version: nlps-base-Zeppelin-6.2.200-B87-GMT20160708224223;', 'nlu_version': '[Version: nlps-fra-FRA-QUICKNLU;Label;3527_NLPS_5;Model;2994b62f-6984-11e6-9cbe-49366b49eae8;Build;5cc9c3e6-730b-11e6-9cbe-cbdea37b47dd;QnluTrain;1.14.5;CreatedAt;2016-09-05T01:52:03.000Z]', 'nmaid': 'NMDPTRIAL_thibault_cohen_nuance_com20150916110537', 'nlu_component_flow': '[Input:TextProcJSON] [NLUlib|C-ising-r$Rev$.f20160617.1703] [Flow|GramURI:/opt/nuance/ncs/nlps-uima-as/datapacks/nlps-nlu/nlps-QUICKNLU/8650//8650/NMDPTRIAL_thibault_cohen_nuance_com20150916110537_master_fra-FRA/5cc9c3e6-730b-11e6-9cbe-cbdea37b47dd/UIMA//trainedInnerGrammar.filter.gram] [Input:TextProcJSON] [NLUlib|C-ising-r$Rev$.f20160617.1703] [Flow|GramURI:/opt/nuance/ncs/nlps-uima-as/datapacks/nlps-nlu/nlps-QUICKNLU/8650//8650/NMDPTRIAL_thibault_cohen_nuance_com20150916110537_master_fra-FRA/5cc9c3e6-730b-11e6-9cbe-cbdea37b47dd/UIMA//trainedInnerGrammar.filter.gram]', 'application': 'NMDPTRIAL_thibault_cohen_nuance_com20150916110537', 'nlu_language': 'fra-FRA', 'qws_project_id': 'b4d065c537ea596e0a8b62c2fcd1bf45b92b1b27c9a5446b', 'nlps_host': 'nlps-dy-qnlu-pool-1-12e1cdd74ad91b2674535fdc6579efc8-3227i:8636', 'nlps_ip': '172.17.7.7', 'nlu_use_literal_annotator': '0', 'nlps_nlu_type': 'quicknludynamic'}}}, 'NMAS_PRFX_SESSION_ID': '6cf6f736-64a8-4f5f-adaf-a148e04a0057'}
1 change: 1 addition & 0 deletions tests/settings/conf/settings_tests_conf_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tux:
app_id: FAKE_APP_ID
app_key: FAKE_APP_KEY
url: https://ws.dev.nuance.com
hotword: "yes"
log_level: DEBUG
fake: True
pins:
Expand Down
1 change: 1 addition & 0 deletions tests/settings/conf/settings_tests_conf_10.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tux:
app_id: FAKE_APP_ID
app_key: FAKE_APP_KEY
url: https://ws.dev.nuance.com
hotword: "yes"
advanced:
log_level: DEBUG
fake: True
Expand Down
1 change: 1 addition & 0 deletions tests/settings/conf/settings_tests_conf_11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tux:
app_id: FAKE_APP_ID
app_key: FAKE_APP_KEY
url: https://ws.dev.nuance.com
hotword: "yes"
advanced:
log_level: DEBUG
fake: True
Expand Down
1 change: 1 addition & 0 deletions tests/settings/conf/settings_tests_conf_12.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tux:
app_id: FAKE_APP_ID
app_key: FAKE_APP_KEY
url: https://ws.dev.nuance.com
hotword: "yes"
advanced:
log_level: DEBUG
fake: True
Expand Down
18 changes: 18 additions & 0 deletions tests/settings/conf/settings_tests_conf_13.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Pins is not a dict
tux:
global:
name: TuxDroid
gender: male
speech:
language: eng-USA
voice: tom
codec: wav
app_id: FAKE_APP_ID
app_key: FAKE_APP_KEY
url: https://ws.dev.nuance.com
hotword: "yes"
advanced:
log_level: DEBUG
fake: True
pins:
wings: badpin
19 changes: 19 additions & 0 deletions tests/settings/conf/settings_tests_conf_14.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Pins is not a dict
tux:
global:
name: TuxDroid
gender: male
speech:
language: eng-USA
voice: tom
codec: wav
app_id: FAKE_APP_ID
app_key: FAKE_APP_KEY
url: https://ws.dev.nuance.com
hotword: "yes"
advanced:
log_level: DEBUG
fake: True
pins:
wings:
4: badpin
22 changes: 22 additions & 0 deletions tests/settings/conf/settings_tests_conf_15.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tux:
advanced:
fake: true
log_level: DEBUG
data: {}
global:
gender: male
name: TuxDroid
pins:
wings:
left_switch: 17
movement: 22
position: 25
right_switch: 4
speech:
app_id: FAKE_APP_ID
app_key: FA1EA331E666
codec: wav
hotword: hello
language: eng-USA
url: https://ws.dev.nuance.com
voice: tom
15 changes: 14 additions & 1 deletion tests/settings/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class SettingsTests(unittest.TestCase):

def test_bad_conf(self):
"""Bad configuration for Tux class"""
"""Bad configuration for Settings class"""
logger = logging.getLogger(name="TestLogger")
# No file
conf_file = "tests/settings/conf/no_file.yaml"
Expand Down Expand Up @@ -55,3 +55,16 @@ def test_bad_conf(self):
# Bad pins section
conf_file = "tests/settings/conf/settings_tests_conf_12.yaml"
self.assertRaises(SettingsError, lambda: Settings(conf_file, logger))
# Bad pins section
conf_file = "tests/settings/conf/settings_tests_conf_13.yaml"
self.assertRaises(SettingsError, lambda: Settings(conf_file, logger))
# Bad pins section
conf_file = "tests/settings/conf/settings_tests_conf_14.yaml"
self.assertRaises(SettingsError, lambda: Settings(conf_file, logger))

def test_good_conf(self):
"""Good configuration for Settings class"""
logger = logging.getLogger(name="TestLogger")
# Good confi
conf_file = "tests/settings/conf/settings_tests_conf_15.yaml"
Settings(conf_file, logger)
7 changes: 3 additions & 4 deletions tests/tux/conf/tux_tests_conf_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ tux:
advanced:
fake: true
log_level: DEBUG
data:
birthday: 1473713243.88349
global:
gender: male
name: TuxDroid
hotword:
answer: "yes"
hotword: hello
model_dir: pocketsphinx-data
pins:
wings:
left_switch: 17
Expand All @@ -19,6 +17,7 @@ tux:
app_id: FAKE_APP_ID
app_key: FA1EA331E666
codec: wav
hotword: hello
language: eng-USA
url: https://ws.dev.nuance.com
voice: tom
6 changes: 2 additions & 4 deletions tests/voice/conf/voice_tests_conf_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ tux:
advanced:
fake: true
log_level: DEBUG
data: {}
global:
gender: male
name: TuxDroid
hotword:
answer: "yes"
hotword: hello
model_dir: pocketsphinx-data
pins:
wings:
left_switch: 17
Expand All @@ -19,6 +16,7 @@ tux:
app_id: FAKE_APP_ID
app_key: FA1EA331E666
codec: wav
hotword: hello
language: eng-USA
url: https://ws.dev.nuance.com
voice: tom

0 comments on commit b58d217

Please sign in to comment.