From 7d80c7d7b6c983cd631986b3c74672389c8916d9 Mon Sep 17 00:00:00 2001 From: schneefux Date: Tue, 30 Dec 2014 19:09:49 +0100 Subject: Split unittests into separate files and move them to tests/ --- tests/test_stt.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_stt.py (limited to 'tests/test_stt.py') diff --git a/tests/test_stt.py b/tests/test_stt.py new file mode 100644 index 0000000..267c1c2 --- /dev/null +++ b/tests/test_stt.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8-*- +import unittest +from client import stt, jasperpath + + +class TestSTT(unittest.TestCase): + + def setUp(self): + self.jasper_clip = jasperpath.data('audio', 'jasper.wav') + self.time_clip = jasperpath.data('audio', 'time.wav') + + self.passive_stt_engine = stt.PocketSphinxSTT.get_passive_instance() + self.active_stt_engine = stt.PocketSphinxSTT.get_active_instance() + + def testTranscribeJasper(self): + """ + Does Jasper recognize his name (i.e., passive listen)? + """ + with open(self.jasper_clip, mode="rb") as f: + transcription = self.passive_stt_engine.transcribe(f) + self.assertIn("JASPER", transcription) + + def testTranscribe(self): + """ + Does Jasper recognize 'time' (i.e., active listen)? + """ + with open(self.time_clip, mode="rb") as f: + transcription = self.active_stt_engine.transcribe(f) + self.assertIn("TIME", transcription) -- cgit v1.3.1 From 87262c75c3e645358e6587b64c8bd2adca9477b2 Mon Sep 17 00:00:00 2001 From: schneefux Date: Tue, 30 Dec 2014 19:37:24 +0100 Subject: Add skip conditions to unittests for dependency checking --- tests/test_g2p.py | 2 +- tests/test_stt.py | 21 +++++++++++++++++++++ tests/test_vocabcompiler.py | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) (limited to 'tests/test_stt.py') diff --git a/tests/test_g2p.py b/tests/test_g2p.py index e18ebff..7904cbf 100644 --- a/tests/test_g2p.py +++ b/tests/test_g2p.py @@ -15,7 +15,7 @@ def phonetisaurus_installed(): return True -@unittest.skipUnless(phonetisaurus_installed, +@unittest.skipUnless(phonetisaurus_installed(), "Phonetisaurus or fst_model not present") class TestG2P(unittest.TestCase): diff --git a/tests/test_stt.py b/tests/test_stt.py index 267c1c2..cb33ff6 100644 --- a/tests/test_stt.py +++ b/tests/test_stt.py @@ -1,9 +1,30 @@ #!/usr/bin/env python2 # -*- coding: utf-8-*- import unittest +import imp from client import stt, jasperpath +def cmuclmtk_installed(): + try: + imp.find_module('cmuclmtk') + except ImportError: + return False + else: + return True + + +def pocketsphinx_installed(): + try: + imp.find_module('pocketsphinx') + except ImportError: + return False + else: + return True + + +@unittest.skipUnless(cmuclmtk_installed(), "CMUCLMTK not present") +@unittest.skipUnless(pocketsphinx_installed(), "Pocketsphinx not present") class TestSTT(unittest.TestCase): def setUp(self): diff --git a/tests/test_vocabcompiler.py b/tests/test_vocabcompiler.py index 561440a..f9e427f 100644 --- a/tests/test_vocabcompiler.py +++ b/tests/test_vocabcompiler.py @@ -90,8 +90,8 @@ class TestVocabulary(unittest.TestCase): self.vocab.compile(phrases, force=True) -@unittest.skipIf(vocabcompiler.cmuclmtk is None, - "CMUCLMTK not present") +@unittest.skipUnless(hasattr(vocabcompiler, 'cmuclmtk'), + "CMUCLMTK not present") class TestPocketsphinxVocabulary(TestVocabulary): VOCABULARY = vocabcompiler.PocketsphinxVocabulary -- cgit v1.3.1