From 0d68acbfb9ba96f1a0b288e3186d5e9c8c3d3650 Mon Sep 17 00:00:00 2001 From: Takuya Nishimoto Date: Mon, 17 Mar 2014 17:04:07 +0900 Subject: [PATCH] fixed tests and updated test.py --- jptools/jtalkPredicTest.py | 15 ++++++++++----- jptools/jtalkRunner.py | 7 ++++++- jptools/mecabRunner.py | 15 ++++++++++++--- jptools/test.cmd | 1 + jptools/test.py | 21 +++++++++++++++++++++ 5 files changed, 50 insertions(+), 9 deletions(-) diff --git a/jptools/jtalkPredicTest.py b/jptools/jtalkPredicTest.py index e87fe11..0b1ca55 100644 --- a/jptools/jtalkPredicTest.py +++ b/jptools/jtalkPredicTest.py @@ -5,9 +5,8 @@ from __future__ import unicode_literals, print_function import os import sys sys.path.append(r'..\source\synthDrivers\jtalk') -from _jtalk_core import * from _nvdajp_unicode import unicode_normalize -import _nvdajp_predic +import jtalkPrepare tests = [ ['ー', 'チョーオン'], @@ -68,11 +67,17 @@ tests = [ def _print(s): print(s.encode('utf-8', 'ignore')) -if __name__ == '__main__': - _nvdajp_predic.setup() +def runTasks(): + jtalkPrepare.setup() + count = 0 for item in tests: msg = item[0] msg = unicode_normalize(msg) - s = _nvdajp_predic.convert(msg) + s = jtalkPrepare.convert(msg) if item[1] != s: _print('expected:%s result:%s' % (item[1], s)) + count += 1 + return count + +if __name__ == '__main__': + runTasks() diff --git a/jptools/jtalkRunner.py b/jptools/jtalkRunner.py index 39a07b8..14463c4 100644 --- a/jptools/jtalkRunner.py +++ b/jptools/jtalkRunner.py @@ -75,8 +75,11 @@ def pa_play(data, samp_rate = 16000): stream.close() p.terminate() +do_print = False + def __print(s): - print(s.encode('cp932', 'ignore')) + if do_print: + print(s.encode('cp932', 'ignore')) def print_code(msg): s = '' @@ -154,8 +157,10 @@ def main(do_play = False, do_write = True, do_log = False): s = msgs[0] fperiod = v['fperiod'] do_synthesis(s, v, do_play, do_write, do_log, fperiod, pitch=50, inflection=50) + return 0 if __name__ == '__main__': + do_print = True main(do_play=False, do_write=True) #prof = cProfile.run("main(do_play=True)", '_cprof.prof') #p = pstats.Stats('_cprof.prof') diff --git a/jptools/mecabRunner.py b/jptools/mecabRunner.py index 9592ce4..d5e0233 100644 --- a/jptools/mecabRunner.py +++ b/jptools/mecabRunner.py @@ -55,9 +55,13 @@ def get_reading(msg): mf = None return reading -if __name__ == '__main__': +def runTasks(enableUserDic=False): print jt_dir, dic, user_dics_org, user_dics - Mecab_initialize(__print, jt_dir, dic, user_dics) + if enableUserDic: + Mecab_initialize(__print, jt_dir, dic, user_dics) + else: + Mecab_initialize(__print, jt_dir, dic) + count = 0 for i in tasks: if isinstance(i, dict): if 'braille' in i: @@ -85,6 +89,7 @@ if __name__ == '__main__': __print('input: ' + item[0]) __print('reading expected: ' + item[1]) __print('reading result: ' + result[0]) + count += 1 if len(item) > 2 and result[1] != item[2]: __print('') __print('') @@ -92,5 +97,9 @@ if __name__ == '__main__': __print('input: ' + item[0]) __print('braille expected: ' + item[2]) __print('braille result: ' + result[1]) + count += 1 + + return count - +if __name__ == '__main__': + runTasks(enableUserDic=True) diff --git a/jptools/test.cmd b/jptools/test.cmd index a8cf777..c8693bc 100644 --- a/jptools/test.cmd +++ b/jptools/test.cmd @@ -1 +1,2 @@ +call userdicBuilder.cmd python test.py diff --git a/jptools/test.py b/jptools/test.py index 8957538..0a5797b 100644 --- a/jptools/test.py +++ b/jptools/test.py @@ -2,6 +2,9 @@ import unittest import jpBrailleRunner +import mecabRunner +import jtalkPredicTest +import jtalkRunner class JpBrailleTests(unittest.TestCase): @@ -13,5 +16,23 @@ class JpBrailleTests(unittest.TestCase): count, outfile = jpBrailleRunner.pass2() self.assertEqual(count, 0) +class MecabTests(unittest.TestCase): + + def test_all(self): + count = mecabRunner.runTasks() + self.assertEqual(count, 0) + +class JtalkPrepareTests(unittest.TestCase): + + def test_all(self): + count = jtalkPredicTest.runTasks() + self.assertEqual(count, 0) + +class JtalkTests(unittest.TestCase): + + def test_jtalk(self): + ret = jtalkRunner.main(do_play=False, do_write=False, do_log=False) + self.assertEqual(ret, 0) + if __name__ == '__main__': unittest.main() -- 2.11.0