From d7aee9421544aaff12fd4c26677085fd555d6728 Mon Sep 17 00:00:00 2001 From: schneefux Date: Thu, 11 Sep 2014 14:11:33 +0200 Subject: Added test for vocabcompiler to `--light` tests and updated travis config --- .travis.yml | 2 +- boot/test.py | 54 ------------------------------------------------------ client/test.py | 6 +----- jasper.py | 7 +++---- 4 files changed, 5 insertions(+), 64 deletions(-) delete mode 100755 boot/test.py diff --git a/.travis.yml b/.travis.yml index a1aea19..09e0aec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ env: script: - "pip install -r client/requirements.txt" - - "cd client && python test.py --light --vocabcompiler" + - "cd client && python test.py --light" diff --git a/boot/test.py b/boot/test.py deleted file mode 100755 index 638ca77..0000000 --- a/boot/test.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python2 -# -*- coding: utf-8-*- -import os - -if os.environ.get('JASPER_HOME') is None: - os.environ['JASPER_HOME'] = '/home/pi' - -import sys -import unittest -from mock import patch -import vocabcompiler - -lib_path = os.path.abspath('../client') -mod_path = os.path.abspath('../client/modules/') - -sys.path.append(lib_path) -sys.path.append(mod_path) - -import g2p - - -class UnorderedList(list): - - def __eq__(self, other): - return sorted(self) == sorted(other) - - -class TestVocabCompiler(unittest.TestCase): - - def testWordExtraction(self): - sentences = "temp_sentences.txt" - dictionary = "temp_dictionary.dic" - languagemodel = "temp_languagemodel.lm" - - words = [ - 'HACKER', 'LIFE', 'FACEBOOK', 'THIRD', 'NO', 'JOKE', - 'NOTIFICATION', 'MEANING', 'TIME', 'TODAY', 'SECOND', - 'BIRTHDAY', 'KNOCK KNOCK', 'INBOX', 'OF', 'NEWS', 'YES', - 'TOMORROW', 'EMAIL', 'WEATHER', 'FIRST', 'MUSIC', 'SPOTIFY' - ] - - with patch.object(g2p, 'translateWords') as translateWords: - with patch.object(vocabcompiler, 'text2lm') as text2lm: - vocabcompiler.compile(sentences, dictionary, languagemodel) - - # 'words' is appended with ['MUSIC', 'SPOTIFY'] - # so must be > 2 to have received WORDS from modules - translateWords.assert_called_once_with(UnorderedList(words)) - self.assertTrue(text2lm.called) - os.remove(sentences) - os.remove(dictionary) - -if __name__ == '__main__': - unittest.main() diff --git a/client/test.py b/client/test.py index 98838d6..8925e66 100644 --- a/client/test.py +++ b/client/test.py @@ -233,13 +233,9 @@ if __name__ == '__main__': description='Test suite for the Jasper client code.') parser.add_argument('--light', action='store_true', help='runs a subset of the tests (only requires Python dependencies)') - parser.add_argument('--vocabcompiler', action='store_true', - help='runs the vocabcompiler test (independently of the --light argument)') args = parser.parse_args() - test_cases = [TestBrain, TestModules] - if args.vocabcompiler: - test_cases.append(TestVocabCompiler) + test_cases = [TestBrain, TestModules, TestVocabCompiler] if not args.light: test_cases.append(TestG2P) test_cases.append(TestMic) diff --git a/jasper.py b/jasper.py index a04216d..f23c18c 100755 --- a/jasper.py +++ b/jasper.py @@ -7,6 +7,7 @@ import traceback import shutil import yaml +from diagnose import Diagnostics from client import vocabcompiler, stt from client import speaker as speak from client.conversation import Conversation @@ -45,11 +46,9 @@ os.environ["PATH"] = path speaker = speak.newSpeaker() def testConnection(): - try: - urllib2.urlopen("http://www.google.com").getcode() + if Diagnostics.check_network_connection(): print "CONNECTED TO INTERNET" - - except urllib2.URLError: + else: print "COULD NOT CONNECT TO NETWORK" speaker.say( "Warning: I was unable to connect to a network. Parts of the system may not work correctly, depending on your setup.") -- cgit v1.3.1