summaryrefslogtreecommitdiff
path: root/tests/test_g2p.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-12-30 19:52:57 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2014-12-30 19:52:57 +0100
commitec3e900b05d07b228f68ed2ab42bfd545ac06b92 (patch)
tree1a9d93728f5edfaa049ddfad2639a3c5cdb64793 /tests/test_g2p.py
parent74b2639b574ecaf600798d234d93e2d807f63021 (diff)
parent87262c75c3e645358e6587b64c8bd2adca9477b2 (diff)
downloadjasper-client-ec3e900b05d07b228f68ed2ab42bfd545ac06b92.tar.gz
jasper-client-ec3e900b05d07b228f68ed2ab42bfd545ac06b92.zip
Merge pull request #270 from Holzhaus/split-unittests
Split unittests into separate files and move them to tests/
Diffstat (limited to 'tests/test_g2p.py')
-rw-r--r--tests/test_g2p.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/test_g2p.py b/tests/test_g2p.py
new file mode 100644
index 0000000..7904cbf
--- /dev/null
+++ b/tests/test_g2p.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8-*-
+import unittest
+import tempfile
+import mock
+from client import g2p
+
+
+def phonetisaurus_installed():
+ try:
+ g2p.PhonetisaurusG2P(**g2p.PhonetisaurusG2P.get_config())
+ except OSError:
+ return False
+ else:
+ return True
+
+
+@unittest.skipUnless(phonetisaurus_installed(),
+ "Phonetisaurus or fst_model not present")
+class TestG2P(unittest.TestCase):
+
+ def setUp(self):
+ self.g2pconverter = 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())
+
+ def testTranslateWords(self):
+ results = self.g2pconverter.translate(self.words).keys()
+ for word in self.words:
+ 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 mock.patch('client.g2p.diagnose.check_executable',
+ return_value=True):
+ with tempfile.NamedTemporaryFile() as f:
+ conf = g2p.PhonetisaurusG2P.get_config().items()
+ with mock.patch.object(g2p.PhonetisaurusG2P, 'get_config',
+ classmethod(lambda cls: dict(conf +
+ [('fst_model', f.name)]))):
+ super(self.__class__, self).setUp()
+
+ def testTranslateWord(self):
+ with mock.patch('subprocess.Popen',
+ return_value=TestPatchedG2P.DummyProc()):
+ super(self.__class__, self).testTranslateWord()
+
+ def testTranslateWords(self):
+ with mock.patch('subprocess.Popen',
+ return_value=TestPatchedG2P.DummyProc()):
+ super(self.__class__, self).testTranslateWords()