OSDN Git Service

fixed tests and updated test.py
authorTakuya Nishimoto <nishimotz@gmail.com>
Mon, 17 Mar 2014 08:04:07 +0000 (17:04 +0900)
committerTakuya Nishimoto <nishimotz@gmail.com>
Mon, 17 Mar 2014 08:04:07 +0000 (17:04 +0900)
jptools/jtalkPredicTest.py
jptools/jtalkRunner.py
jptools/mecabRunner.py
jptools/test.cmd
jptools/test.py

index e87fe11..0b1ca55 100644 (file)
@@ -5,9 +5,8 @@ from __future__ import unicode_literals, print_function
 import os\r
 import sys\r
 sys.path.append(r'..\source\synthDrivers\jtalk')\r
-from _jtalk_core import *\r
 from _nvdajp_unicode import unicode_normalize\r
-import _nvdajp_predic\r
+import jtalkPrepare\r
 \r
 tests = [\r
        ['ー', 'チョーオン'],\r
@@ -68,11 +67,17 @@ tests = [
 def _print(s):\r
        print(s.encode('utf-8', 'ignore'))\r
 \r
-if __name__ == '__main__':\r
-       _nvdajp_predic.setup()\r
+def runTasks():\r
+       jtalkPrepare.setup()\r
+       count = 0\r
        for item in tests:\r
                msg = item[0]\r
                msg = unicode_normalize(msg)\r
-               s = _nvdajp_predic.convert(msg)\r
+               s = jtalkPrepare.convert(msg)\r
                if item[1] != s:\r
                        _print('expected:%s result:%s' % (item[1], s))\r
+                       count += 1\r
+       return count\r
+\r
+if __name__ == '__main__':\r
+       runTasks()\r
index 39a07b8..14463c4 100644 (file)
@@ -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')
index 9592ce4..d5e0233 100644 (file)
@@ -55,9 +55,13 @@ def get_reading(msg):
        mf = None\r
        return reading\r
 \r
-if __name__ == '__main__':\r
+def runTasks(enableUserDic=False):\r
        print jt_dir, dic, user_dics_org, user_dics\r
-       Mecab_initialize(__print, jt_dir, dic, user_dics)\r
+       if enableUserDic:\r
+               Mecab_initialize(__print, jt_dir, dic, user_dics)\r
+       else:\r
+               Mecab_initialize(__print, jt_dir, dic)\r
+       count = 0\r
        for i in tasks:\r
                if isinstance(i, dict):\r
                        if 'braille' in i:\r
@@ -85,6 +89,7 @@ if __name__ == '__main__':
                        __print('input:    ' + item[0])\r
                        __print('reading expected: ' + item[1])\r
                        __print('reading result:   ' + result[0])\r
+                       count += 1\r
                if len(item) > 2 and result[1] != item[2]:\r
                        __print('')\r
                        __print('')\r
@@ -92,5 +97,9 @@ if __name__ == '__main__':
                        __print('input:            ' + item[0])\r
                        __print('braille expected: ' + item[2])\r
                        __print('braille result:   ' + result[1])\r
+                       count += 1\r
+\r
+       return count\r
 \r
-       \r
+if __name__ == '__main__':\r
+       runTasks(enableUserDic=True)\r
index a8cf777..c8693bc 100644 (file)
@@ -1 +1,2 @@
+call userdicBuilder.cmd
 python test.py
index 8957538..0a5797b 100644 (file)
@@ -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()