Skip to content

Commit 485fde7

Browse files
committed
Changed vocabcompiler test cases
1 parent f3f7e40 commit 485fde7

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

client/test.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import sys
55
import unittest
6+
import tempfile
7+
import shutil
68
import argparse
79
from mock import patch
810
from urllib2 import URLError, urlopen
@@ -31,28 +33,30 @@ def __eq__(self, other):
3133

3234
class TestVocabCompiler(unittest.TestCase):
3335

34-
def testWordExtraction(self):
35-
sentences = "temp_sentences.txt"
36-
dictionary = "temp_dictionary.dic"
37-
languagemodel = "temp_languagemodel.lm"
38-
39-
words = [
36+
def testPhraseExtraction(self):
37+
expected_phrases = sorted([
4038
'HACKER', 'LIFE', 'FACEBOOK', 'THIRD', 'NO', 'JOKE',
4139
'NOTIFICATION', 'MEANING', 'TIME', 'TODAY', 'SECOND',
4240
'BIRTHDAY', 'KNOCK KNOCK', 'INBOX', 'OF', 'NEWS', 'YES',
4341
'TOMORROW', 'EMAIL', 'WEATHER', 'FIRST', 'MUSIC', 'SPOTIFY'
44-
]
45-
46-
with patch.object(g2p, 'translateWords') as translateWords:
47-
with patch.object(vocabcompiler, 'text2lm') as text2lm:
48-
vocabcompiler.compile(sentences, dictionary, languagemodel)
49-
50-
# 'words' is appended with ['MUSIC', 'SPOTIFY']
51-
# so must be > 2 to have received WORDS from modules
52-
translateWords.assert_called_once_with(UnorderedList(words))
53-
self.assertTrue(text2lm.called)
54-
os.remove(sentences)
55-
os.remove(dictionary)
42+
])
43+
44+
extracted_phrases = vocabcompiler.get_all_phrases()
45+
self.assertTrue(extracted_phrases == extracted_phrases)
46+
47+
def testVocabulary(self):
48+
phrases = ['THIS IS A TEST']
49+
50+
tempdir = tempfile.mkdtemp()
51+
52+
vocab = vocabcompiler.DummyVocabulary(path=tempdir)
53+
self.assertTrue(vocab.compiled_revision is None)
54+
self.assertTrue(not vocab.is_compiled)
55+
vocab.compile(phrases)
56+
self.assertTrue(vocab.is_compiled)
57+
self.assertTrue(vocab.matches_phrases(phrases))
58+
59+
shutil.rmtree(tempdir)
5660

5761
class TestMic(unittest.TestCase):
5862

0 commit comments

Comments
 (0)