From 9b7bfec7af923812fdcf5c9faeb98c7c611ea6de Mon Sep 17 00:00:00 2001 From: schneefux Date: Tue, 30 Dec 2014 20:17:15 +0100 Subject: Avoid skipping too many tests (raises test coverage on travis-ci) --- tests/test_g2p.py | 24 +++++++++++++++--------- tests/test_vocabcompiler.py | 12 ++++-------- 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/test_g2p.py b/tests/test_g2p.py index 7904cbf..ad1e171 100644 --- a/tests/test_g2p.py +++ b/tests/test_g2p.py @@ -15,22 +15,24 @@ def phonetisaurus_installed(): return True +WORDS = ['GOOD', 'BAD', 'UGLY'] + + @unittest.skipUnless(phonetisaurus_installed(), "Phonetisaurus or fst_model not present") class TestG2P(unittest.TestCase): def setUp(self): - self.g2pconverter = g2p.PhonetisaurusG2P( + self.g2pconv = g2p.PhonetisaurusG2P( **g2p.PhonetisaurusG2P.get_config()) - self.words = ['GOOD', 'BAD', 'UGLY'] def testTranslateWord(self): - for word in self.words: - self.assertIn(word, self.g2pconverter.translate(word).keys()) + for word in WORDS: + self.assertIn(word, self.g2pconv.translate(word).keys()) def testTranslateWords(self): - results = self.g2pconverter.translate(self.words).keys() - for word in self.words: + results = self.g2pconv.translate(WORDS).keys() + for word in WORDS: self.assertIn(word, results) @@ -58,14 +60,18 @@ class TestPatchedG2P(TestG2P): with mock.patch.object(g2p.PhonetisaurusG2P, 'get_config', classmethod(lambda cls: dict(conf + [('fst_model', f.name)]))): - super(self.__class__, self).setUp() + self.g2pconv = g2p.PhonetisaurusG2P( + **g2p.PhonetisaurusG2P.get_config()) def testTranslateWord(self): with mock.patch('subprocess.Popen', return_value=TestPatchedG2P.DummyProc()): - super(self.__class__, self).testTranslateWord() + for word in WORDS: + self.assertIn(word, self.g2pconv.translate(word).keys()) def testTranslateWords(self): with mock.patch('subprocess.Popen', return_value=TestPatchedG2P.DummyProc()): - super(self.__class__, self).testTranslateWords() + results = self.g2pconv.translate(WORDS).keys() + for word in WORDS: + self.assertIn(word, results) diff --git a/tests/test_vocabcompiler.py b/tests/test_vocabcompiler.py index f9e427f..2ce977d 100644 --- a/tests/test_vocabcompiler.py +++ b/tests/test_vocabcompiler.py @@ -90,22 +90,19 @@ class TestVocabulary(unittest.TestCase): self.vocab.compile(phrases, force=True) -@unittest.skipUnless(hasattr(vocabcompiler, 'cmuclmtk'), - "CMUCLMTK not present") class TestPocketsphinxVocabulary(TestVocabulary): VOCABULARY = vocabcompiler.PocketsphinxVocabulary + @unittest.skipUnless(hasattr(vocabcompiler, 'cmuclmtk'), + "CMUCLMTK not present") def testVocabulary(self): super(TestPocketsphinxVocabulary, self).testVocabulary() self.assertIsInstance(self.vocab.decoder_kwargs, dict) self.assertIn('lm', self.vocab.decoder_kwargs) self.assertIn('dict', self.vocab.decoder_kwargs) - -class TestPatchedPocketsphinxVocabulary(TestPocketsphinxVocabulary): - - def testVocabulary(self): + def testPatchedVocabulary(self): def write_test_vocab(text, output_file): with open(output_file, "w") as f: @@ -135,5 +132,4 @@ class TestPatchedPocketsphinxVocabulary(TestPocketsphinxVocabulary): mocked_cmuclmtk.text2vocab = write_test_vocab mocked_cmuclmtk.text2lm = write_test_lm with mock.patch('client.vocabcompiler.PhonetisaurusG2P', DummyG2P): - super(TestPatchedPocketsphinxVocabulary, - self).testVocabulary() + self.testVocabulary() -- cgit v1.3.1