diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-10-07 14:24:19 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-10-08 20:53:10 +0200 |
| commit | 63aa78e9029de4059c0306926bfd1943cf07492e (patch) | |
| tree | f463e0dc9d722d6863ac0ac66d7c55d99c9aeb7f /client/test.py | |
| parent | f9db756c18723abcacd54ad0667f69babca4c695 (diff) | |
| download | jasper-client-63aa78e9029de4059c0306926bfd1943cf07492e.tar.gz jasper-client-63aa78e9029de4059c0306926bfd1943cf07492e.zip | |
Add unittests for G2P without phonetisaurus
Diffstat (limited to 'client/test.py')
| -rw-r--r-- | client/test.py | 41 |
1 files changed, 40 insertions, 1 deletions
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<s> G UH D </s>\n" + + "GOOD\t14.4036\t<s> G UW D </s>\n" + + "GOOD\t16.0258\t<s> G UH D IY </s>\n" + + "BAD\t0.7416\t<s> B AE D </s>\n" + + "BAD\t12.5495\t<s> B AA D </s>\n" + + "BAD\t13.6745\t<s> B AH D </s>\n" + + "UGLY\t12.572\t<s> AH G L IY </s>\n" + + "UGLY\t17.9278\t<s> Y UW G L IY </s>\n" + + "UGLY\t18.9617\t<s> AH G L AY </s>\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) |
