diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-10-08 16:50:56 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-10-08 20:53:10 +0200 |
| commit | baa4d68705def31614509bd4fdcb3438f175a985 (patch) | |
| tree | a0d2093a1d783c4b0d7de0e3343e14f22b4442a9 | |
| parent | 6d4028cb6b76f759ac38bd091cad8d6bd662bb93 (diff) | |
| download | jasper-client-baa4d68705def31614509bd4fdcb3438f175a985.tar.gz jasper-client-baa4d68705def31614509bd4fdcb3438f175a985.zip | |
Further improve unittest coverage
| -rw-r--r-- | client/test.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/client/test.py b/client/test.py index ac25b41..7ab1761 100644 --- a/client/test.py +++ b/client/test.py @@ -88,10 +88,11 @@ class TestVocabulary(unittest.TestCase): class StrangeCompilationError(Exception): pass - with self.assertRaises(StrangeCompilationError): - with patch.object(self.vocab, '_compile_vocabulary', - side_effect=StrangeCompilationError('test')): + with patch.object(self.vocab, '_compile_vocabulary', + side_effect=StrangeCompilationError('test')): + with self.assertRaises(StrangeCompilationError): self.vocab.compile(phrases) + with self.assertRaises(StrangeCompilationError): with patch('os.remove', side_effect=OSError('test')): self.vocab.compile(phrases) @@ -130,17 +131,27 @@ class TestPatchedPocketsphinxVocabulary(TestPocketsphinxVocabulary): with open(output_file, "w") as f: f.write("TEST") + class DummyG2P(object): + def __init__(self, *args, **kwargs): + pass + + @classmethod + def get_config(self, *args, **kwargs): + return {} + + def translate(self, *args, **kwargs): + return {'GOOD': ['G UH D', + 'G UW D'], + 'BAD': ['B AE D'], + 'UGLY': ['AH G L IY']} + with patch('vocabcompiler.cmuclmtk', create=True) as mocked_cmuclmtk: mocked_cmuclmtk.text2vocab = write_test_vocab mocked_cmuclmtk.text2lm = write_test_lm - with patch.object(g2p.PhonetisaurusG2P, '__new__', - create=True) as mocked_g2p: - mocked_g2p.translate.return_value = (lambda *args, **kwargs: - {'GOOD': ['G UH D'], - 'BAD': ['B AE D'], - 'UGLY': ['AH G L IY']}) - super(TestPatchedPocketsphinxVocabulary, self).testVocabulary() + with patch('vocabcompiler.PhonetisaurusG2P', DummyG2P): + super(TestPatchedPocketsphinxVocabulary, + self).testVocabulary() class TestMic(unittest.TestCase): |
