Browse Source

Pass minimum test set.

scossu 6 tháng trước cách đây
mục cha
commit
7e0722d359

+ 6 - 7
tests/data/script_samples/unittest.csv

@@ -1,7 +1,6 @@
-inherited,abcd,ABCD,,
-inherited,ABCD,abcd,"{""dir"": ""r2s""}",
-inherited,ab,90,,
-rot3,abcd,defg,,
-rot3,HIJK,KLMN,,
-rot3,pqrs,Pqrs,"{""capitalize"": ""first""}",
-rot3,pqrs,PQRS,"{""capitalize"": ""all""}",
+inherited,abcd,9078,,
+inherited,TUVX,tuvx,"{""t_dir"": ""r2s""}",
+rot3,defg,abcd,,
+rot3,HIJK,KLMN,"{""t_dir"": ""r2s""}",
+rot3,st uv,Vw xy,"{""t_dir"": ""r2s"", ""capitalize"": ""first""}",
+rot3,st uv,Vw Xy,"{""t_dir"": ""r2s"", ""capitalize"": ""all""}",

+ 1 - 2
tests/test01_cfg.py

@@ -1,11 +1,10 @@
 from os import environ, unlink
 from unittest import TestCase
 
-from scriptshifter.tables import get_language
+from scriptshifter.tables import get_language, init_db
 
 
 def setUpModule():
-    from scriptshifter.tables import init_db
     init_db()
 
 

+ 11 - 33
tests/test02_transliteration.py

@@ -6,7 +6,7 @@ from json import loads as jloads
 from os import environ, path, unlink
 
 from scriptshifter.trans import transliterate
-from scriptshifter.tables import get_language
+from scriptshifter.tables import get_language, init_db
 from tests import TEST_DATA_DIR
 
 
@@ -14,7 +14,6 @@ logger = logging.getLogger(__name__)
 
 
 def setUpModule():
-    from scriptshifter.tables import init_db
     init_db()
 
 
@@ -31,12 +30,9 @@ class TestTrans(TestCase):
     TODO use a comprehensive sample table and report errors for unsupported
     languages.
     """
-
-    maxDiff = None
-
-    def sample_s2r(self):
+    def sample(self):
         """
-        Test S2R transliteration for one CSV sample.
+        Test transliteration for one CSV row.
 
         This function name won't start with `test_` otherwise will be
         automatically run without parameters.
@@ -45,6 +41,7 @@ class TestTrans(TestCase):
         if config["has_s2r"]:
             txl = transliterate(
                     self.script, self.tbl,
+                    t_dir=self.options.get("t_dir", "s2r"),
                     capitalize=self.options.get("capitalize", False),
                     options=self.options)[0]
             self.assertEqual(
@@ -52,25 +49,6 @@ class TestTrans(TestCase):
                     f"S2R transliteration error for {self.tbl}!\n"
                     f"Original: {self.script}")
 
-    def sample_r2s(self):
-        """
-        Test R2S transliteration for one CSV sample.
-
-        This function name won't start with `test_` otherwise will be
-        automatically run without parameters.
-        """
-        config = get_language(self.tbl)
-        if config["has_r2s"]:
-            txl = transliterate(
-                    self.roman, self.tbl,
-                    t_dir="r2s",
-                    capitalize=self.options.get("capitalize", False),
-                    options=self.options)[0]
-            self.assertEqual(
-                    txl, self.script,
-                    f"R2S transliteration error for {self.tbl}!\n"
-                    f"Original: {self.roman}")
-
 
 def make_suite():
     """
@@ -85,13 +63,13 @@ def make_suite():
         for row in csv:
             if len(row[0]):
                 # Inject transliteration info in the test case.
-                for tname in ("sample_s2r", "sample_r2s"):
-                    tcase = TestTrans(tname)
-                    tcase.tbl = row[0]
-                    tcase.script = row[1].strip()
-                    tcase.roman = row[2].strip()
-                    tcase.options = jloads(row[3]) if len(row[3]) else {}
-                    suite.addTest(tcase)
+                tcase = TestTrans("sample")
+                tcase.tbl = row[0]
+                tcase.script = row[1].strip()
+                tcase.roman = row[2].strip()
+                tcase.options = jloads(row[3]) if len(row[3]) else {}
+
+                suite.addTest(tcase)
 
     return suite
 

+ 1 - 1
tests/test03_capitalization.py

@@ -2,10 +2,10 @@ from os import environ, unlink
 from unittest import TestCase
 
 from scriptshifter.trans import transliterate
+from scriptshifter.tables import init_db
 
 
 def setUpModule():
-    from scriptshifter.tables import init_db
     init_db()
 
 

+ 1 - 1
tests/test04_rest_api.py

@@ -4,13 +4,13 @@ from os import environ, unlink
 from unittest import TestCase
 
 from scriptshifter.rest_api import app
+from scriptshifter.tables import init_db
 
 
 EP = "http://localhost:8000"
 
 
 def setUpModule():
-    from scriptshifter.tables import init_db
     init_db()