summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-05-26 23:43:33 -0700
committerschneefux <schneefux+commit@schneefux.xyz>2014-05-26 23:43:33 -0700
commit546d050fcb1c114ad828593a4133f90f20966268 (patch)
tree4dda2176d5526794aa3500fbbdc49cf352a4da6e
parent79b5d466202ecfeaae3d9472ed89d4f94ab66450 (diff)
downloadjasper-client-546d050fcb1c114ad828593a4133f90f20966268.tar.gz
jasper-client-546d050fcb1c114ad828593a4133f90f20966268.zip
basic unit test for vocabcompiler
-rw-r--r--boot/test.py36
-rw-r--r--boot/vocabcompiler.py5
2 files changed, 39 insertions, 2 deletions
diff --git a/boot/test.py b/boot/test.py
new file mode 100644
index 0000000..1c03a33
--- /dev/null
+++ b/boot/test.py
@@ -0,0 +1,36 @@
+import os
+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 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(words)
+ self.assertTrue(text2lm.called)
+ os.remove(sentences)
+ os.remove(dictionary)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/boot/vocabcompiler.py b/boot/vocabcompiler.py
index a3aaf66..33fb0a8 100644
--- a/boot/vocabcompiler.py
+++ b/boot/vocabcompiler.py
@@ -48,6 +48,7 @@ def compile(sentences, dictionary, languagemodel):
pass # module probably doesn't have the property
words = list(set(words))
+ print words
# for spotify module
words.extend(["MUSIC", "SPOTIFY"])
@@ -57,11 +58,11 @@ def compile(sentences, dictionary, languagemodel):
zipped = zip(words, pronounced)
lines = ["%s %s" % (x, y) for x, y in zipped]
- with open(dictionary, "w") as f:
+ with open(dictionary, "w+") as f:
f.write("\n".join(lines) + "\n")
# create the language model
- with open(sentences, "w") as f:
+ with open(sentences, "w+") as f:
f.write("\n".join(words) + "\n")
f.write("<s> \n </s> \n")
f.close()