diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-24 19:39:16 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-10-08 20:52:13 +0200 |
| commit | b13fbec234292c46af2af37be0387d98a15ba2bf (patch) | |
| tree | 1fa0b5b1c940d49a8fff9f23a8888b500af420ad /client/test.py | |
| parent | 9633fdeb0118f5e05c7e9eebd154a49f5ef85209 (diff) | |
| download | jasper-client-b13fbec234292c46af2af37be0387d98a15ba2bf.tar.gz jasper-client-b13fbec234292c46af2af37be0387d98a15ba2bf.zip | |
Changed vocabcompiler test cases
Diffstat (limited to 'client/test.py')
| -rw-r--r-- | client/test.py | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/client/test.py b/client/test.py index 6858700..9f9be8a 100644 --- a/client/test.py +++ b/client/test.py @@ -4,6 +4,8 @@ import os import sys import unittest import logging +import tempfile +import shutil import argparse from mock import patch, Mock @@ -32,31 +34,31 @@ class UnorderedList(list): class TestVocabCompiler(unittest.TestCase): - def testWordExtraction(self): - sentences = "temp_sentences.txt" - dictionary = "temp_dictionary.dic" - languagemodel = "temp_languagemodel.lm" - - words = [] + def testPhraseExtraction(self): + expected_phrases = ['MOCK'] mock_module = Mock() - mock_module.WORDS = [ - 'MOCK' - ] + mock_module.WORDS = ['MOCK'] + + with patch.object(brain.Brain, 'get_modules', + classmethod(lambda cls: [mock_module])): + extracted_phrases = vocabcompiler.get_all_phrases() + self.assertEqual(expected_phrases, extracted_phrases) + + def testVocabulary(self): + phrases = ['THIS IS A TEST'] - words.extend(mock_module.WORDS) + tempdir = tempfile.mkdtemp() - with patch.object(g2p, 'translateWords') as translateWords: - with patch.object(vocabcompiler, 'text2lm') as text2lm: - with patch.object(brain.Brain, 'get_modules', - classmethod(lambda cls: [mock_module])): - vocabcompiler.compile(sentences, dictionary, languagemodel) + vocab = vocabcompiler.DummyVocabulary(path=tempdir) + self.assertIsNone(vocab.compiled_revision) + self.assertFalse(vocab.is_compiled) + vocab.compile(phrases) + self.assertIsNotNone(vocab.compiled_revision) + self.assertTrue(vocab.is_compiled) + self.assertTrue(vocab.matches_phrases(phrases)) - translateWords.assert_called_once_with( - UnorderedList(words)) - self.assertTrue(text2lm.called) - os.remove(sentences) - os.remove(dictionary) + shutil.rmtree(tempdir) class TestMic(unittest.TestCase): |
