summaryrefslogtreecommitdiff
path: root/client/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'client/test.py')
-rw-r--r--client/test.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/client/test.py b/client/test.py
index a8f12be..8925e66 100644
--- a/client/test.py
+++ b/client/test.py
@@ -11,8 +11,10 @@ import argparse
from mock import patch
from urllib2 import URLError, urlopen
import test_mic
+import vocabcompiler
import g2p
import brain
+from diagnose import Diagnostics
DEFAULT_PROFILE = {
'prefers_email': False,
@@ -21,14 +23,38 @@ DEFAULT_PROFILE = {
'phone_number': '012344321'
}
-
def activeInternet():
- try:
- urlopen('http://www.google.com', timeout=1)
- return True
- except URLError:
- return False
+ return Diagnostics.check_network_connection()
+
+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)
class TestMic(unittest.TestCase):
@@ -209,7 +235,7 @@ if __name__ == '__main__':
help='runs a subset of the tests (only requires Python dependencies)')
args = parser.parse_args()
- test_cases = [TestBrain, TestModules]
+ test_cases = [TestBrain, TestModules, TestVocabCompiler]
if not args.light:
test_cases.append(TestG2P)
test_cases.append(TestMic)