瀏覽代碼

WIP Add tests for regex ignore patterns.

scossu 6 月之前
父節點
當前提交
efb27b8707
共有 5 個文件被更改,包括 22 次插入3 次删除
  1. 1 1
      sscli
  2. 2 0
      tests/data/script_samples/unittest.csv
  3. 11 0
      tests/tables/data/regex.yml
  4. 3 0
      tests/tables/index.yml
  5. 5 2
      tests/test02_transliteration.py

+ 1 - 1
sscli

@@ -10,7 +10,7 @@ from os import path
 
 from scriptshifter import DB_PATH
 from scriptshifter.tables import init_db as _init_db
-from tests import test_sample
+from tests.integration_tests import test_sample
 
 
 @click.group()

+ 2 - 0
tests/data/script_samples/unittest.csv

@@ -4,3 +4,5 @@ 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""}",
+regex,Hello abc,Hello 907,"{""t_dir"": ""r2s""}",
+regex,Hollo abc,Hollo 907,"{""t_dir"": ""r2s""}",

+ 11 - 0
tests/tables/data/regex.yml

@@ -0,0 +1,11 @@
+---
+# Test file for regex ignoring.
+
+general:
+  name: Test regex ignoring.
+  parents:
+    - inherited
+
+roman_to_script:
+  ignore_ptn:
+    - "[hH][aeu]llo"

+ 3 - 0
tests/tables/index.yml

@@ -1,3 +1,4 @@
+---
 inherited:
   name: Test inheritance leaf file
   marc_code: inh
@@ -10,5 +11,7 @@ cap_inherited:
   name: Test capitalization
 ordering:
   name: Test ordering
+regex:
+  name: inherited config + regex ignore.
 rot3:
   name: Test ROT3 hooks

+ 5 - 2
tests/test02_transliteration.py

@@ -38,10 +38,13 @@ class TestTrans(TestCase):
         automatically run without parameters.
         """
         config = get_language(self.tbl)
-        if config["has_s2r"]:
+        t_dir = self.options.get("t_dir", "s2r")
+        if (
+                t_dir == "s2r" and config["has_s2r"]
+                or t_dir == "r2s" and config["has_r2s"]):
             txl = transliterate(
                     self.script, self.tbl,
-                    t_dir=self.options.get("t_dir", "s2r"),
+                    t_dir=t_dir,
                     capitalize=self.options.get("capitalize", False),
                     options=self.options)[0]
             self.assertEqual(