From b13fbec234292c46af2af37be0387d98a15ba2bf Mon Sep 17 00:00:00 2001 From: schneefux Date: Wed, 24 Sep 2014 19:39:16 +0200 Subject: Changed vocabcompiler test cases --- client/test.py | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'client') 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' - ] - - words.extend(mock_module.WORDS) - - 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) - - translateWords.assert_called_once_with( - UnorderedList(words)) - self.assertTrue(text2lm.called) - os.remove(sentences) - os.remove(dictionary) + 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'] + + tempdir = tempfile.mkdtemp() + + 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)) + + shutil.rmtree(tempdir) class TestMic(unittest.TestCase): -- cgit v1.3.1