From 63aa78e9029de4059c0306926bfd1943cf07492e Mon Sep 17 00:00:00 2001 From: schneefux Date: Tue, 7 Oct 2014 14:24:19 +0200 Subject: Add unittests for G2P without phonetisaurus --- client/test.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'client/test.py') diff --git a/client/test.py b/client/test.py index 0034974..079ba92 100644 --- a/client/test.py +++ b/client/test.py @@ -100,6 +100,43 @@ class TestG2P(unittest.TestCase): self.assertIn(word, results) +class TestPatchedG2P(TestG2P): + class DummyProc(object): + def __init__(self, *args, **kwargs): + self.returncode = 0 + + def communicate(self): + return ("GOOD\t9.20477\t G UH D \n" + + "GOOD\t14.4036\t G UW D \n" + + "GOOD\t16.0258\t G UH D IY \n" + + "BAD\t0.7416\t B AE D \n" + + "BAD\t12.5495\t B AA D \n" + + "BAD\t13.6745\t B AH D \n" + + "UGLY\t12.572\t AH G L IY \n" + + "UGLY\t17.9278\t Y UW G L IY \n" + + "UGLY\t18.9617\t AH G L AY \n", "") + + def setUp(self): + with patch.object(g2p.PhonetisaurusG2P, 'executable_found', + classmethod(lambda cls: True)): + with tempfile.NamedTemporaryFile() as f: + conf = g2p.PhonetisaurusG2P.get_config().items() + with patch.object(g2p.PhonetisaurusG2P, 'get_config', + classmethod(lambda cls: dict( + conf + [('fst_model', f.name)]))): + super(self.__class__, self).setUp() + + def testTranslateWord(self): + with patch('subprocess.Popen', + return_value=TestPatchedG2P.DummyProc()): + super(self.__class__, self).testTranslateWord() + + def testTranslateWords(self): + with patch('subprocess.Popen', + return_value=TestPatchedG2P.DummyProc()): + super(self.__class__, self).testTranslateWords() + + class TestDiagnose(unittest.TestCase): def testPythonImportCheck(self): # This a python stdlib module that definitely exists @@ -270,7 +307,9 @@ if __name__ == '__main__': test_cases = [TestBrain, TestModules, TestVocabCompiler, TestTTS, TestDiagnose] - if not args.light: + if args.light: + test_cases.append(TestPatchedG2P) + else: test_cases.append(TestG2P) test_cases.append(TestMic) -- cgit v1.3.1