|
3 | 3 | import os |
4 | 4 | import sys |
5 | 5 | import unittest |
| 6 | +import tempfile |
| 7 | +import shutil |
6 | 8 | import argparse |
7 | 9 | from mock import patch |
8 | 10 | from urllib2 import URLError, urlopen |
@@ -31,28 +33,30 @@ def __eq__(self, other): |
31 | 33 |
|
32 | 34 | class TestVocabCompiler(unittest.TestCase): |
33 | 35 |
|
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([ |
40 | 38 | 'HACKER', 'LIFE', 'FACEBOOK', 'THIRD', 'NO', 'JOKE', |
41 | 39 | 'NOTIFICATION', 'MEANING', 'TIME', 'TODAY', 'SECOND', |
42 | 40 | 'BIRTHDAY', 'KNOCK KNOCK', 'INBOX', 'OF', 'NEWS', 'YES', |
43 | 41 | '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) |
56 | 60 |
|
57 | 61 | class TestMic(unittest.TestCase): |
58 | 62 |
|
|
0 commit comments