Skip to content

Commit

Permalink
fix and refactor stardict tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 18, 2024
1 parent 78c980b commit 81f0fce
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions tests/g_stardict_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ class TestGlossaryStarDictBase(TestGlossaryErrorsBase):
def convert_txt_stardict( # noqa: PLR0913
self,
fname,
fname2="",
sdDirName,
syn=True,
dictzip=False,
config=None,
writeOptions=None,
info=None,
**convertArgs,
):
if not fname2:
fname2 = fname

binExtList = ["idx", "dict"]
if syn:
binExtList.append("syn")
Expand Down Expand Up @@ -59,13 +56,13 @@ def convert_txt_stardict( # noqa: PLR0913

self.compareTextFiles(
outputFilename,
self.downloadFile(f"{fname2}.sd/{fname2}.ifo"),
self.downloadFile(f"{sdDirName}/{fname}.ifo"),
)

for ext in binExtList:
self.compareBinaryFiles(
otherFiles[ext],
self.downloadFile(f"{fname2}.sd/{fname2}.{ext}"),
self.downloadFile(f"{sdDirName}/{fname}.{ext}"),
)

def convert_txt_stardict_zip( # noqa: PLR0913
Expand Down Expand Up @@ -105,6 +102,7 @@ def convert_txt_stardict_zip( # noqa: PLR0913
def convert_stardict_txt(
self,
inputFname: str,
inputDirName: str,
outputFname: str,
testId: str,
syn=True,
Expand All @@ -114,9 +112,9 @@ def convert_stardict_txt(
if syn:
binExtList.append("syn")
for ext in binExtList:
self.downloadFile(f"{inputFname}.sd/{inputFname}.{ext}")
self.downloadFile(f"{inputDirName}/{inputFname}.{ext}")

inputFilename = self.downloadFile(f"{inputFname}.sd/{inputFname}.ifo")
inputFilename = self.downloadFile(f"{inputDirName}/{inputFname}.ifo")
outputFilename = self.newTempFilePath(
f"{inputFname}-{testId}.txt",
)
Expand Down Expand Up @@ -145,14 +143,16 @@ def __init__(self, *args, **kwargs):
"004-bar.sd/004-bar.idx": "cf9440cf",
"004-bar.sd/004-bar.ifo": "ada870e4",
"004-bar.sd/004-bar.syn": "286b17bf",
"100-en-de-v4.sd/100-en-de-v4.dict": "5a97476f",
"100-en-de-v4.sd/100-en-de-v4.idx": "a99f29d2",
"100-en-de-v4.sd/100-en-de-v4.ifo": "2120708c",
"100-en-fa.sd/100-en-fa.dict": "223a0d1d",
"100-en-fa.sd/100-en-fa.idx": "6df43378",
"100-en-fa.sd/100-en-fa.ifo": "bb916827",
"100-en-fa.sd/100-en-fa.syn": "1160fa0b",
"100-en-fa-sd.txt": "0b8b2ac0",

"100-en-de-v4-sd-v2/100-en-de-v4.dict": "5a97476f",
"100-en-de-v4-sd-v2/100-en-de-v4.idx": "a99f29d2",
"100-en-de-v4-sd-v2/100-en-de-v4.ifo": "2120708c",
"100-en-fa-sd-v2/100-en-fa.dict": "223a0d1d",
"100-en-fa-sd-v2/100-en-fa.idx": "6df43378",
"100-en-fa-sd-v2/100-en-fa.ifo": "bb916827",
"100-en-fa-sd-v2/100-en-fa.syn": "1160fa0b",
"100-en-fa-sd-v2.txt": "0b8b2ac0",

# FIXME: remove empty description line from 100-en-fa.ifo
# stardict-mixed-types-1.ifo, "stardict-mixed-types-2.ifo
"100-ja-en.sd/100-ja-en.dict": "39715f01",
Expand Down Expand Up @@ -183,6 +183,7 @@ def __init__(self, *args, **kwargs):
def test_convert_txt_stardict_0(self):
self.convert_txt_stardict(
"100-en-fa",
"100-en-fa-sd-v2",
config={"auto_sqlite": True},
direct=True,
)
Expand All @@ -191,6 +192,7 @@ def test_convert_txt_stardict_1(self):
for sqlite in (None, False, True):
self.convert_txt_stardict(
"100-en-fa",
"100-en-fa-sd-v2",
sqlite=sqlite,
)

Expand All @@ -212,13 +214,15 @@ def test_convert_txt_stardict_2(self):
for sqlite in (None, False, True):
self.convert_txt_stardict(
"004-bar",
"004-bar.sd",
sqlite=sqlite,
)

def test_convert_txt_stardict_3(self):
for sqlite in (None, False, True):
self.convert_txt_stardict(
"100-en-de-v4",
"100-en-de-v4-sd-v2",
syn=False,
sqlite=sqlite,
)
Expand All @@ -227,6 +231,7 @@ def test_convert_txt_stardict_4(self):
for sqlite in (None, False, True):
self.convert_txt_stardict(
"100-ja-en",
"100-ja-en.sd",
syn=True,
sqlite=sqlite,
)
Expand All @@ -235,13 +240,15 @@ def test_convert_txt_stardict_5(self):
for sqlite in (None, False, True):
self.convert_txt_stardict(
"300-ru-en",
"300-ru-en.sd",
syn=True,
sqlite=sqlite,
)

def test_convert_txt_stardict_sqlite_no_alts(self):
self.convert_txt_stardict(
"100-en-fa",
"100-en-fa-sd-v2",
config={"enable_alts": False},
sqlite=True,
)
Expand All @@ -252,14 +259,16 @@ def test_convert_txt_stardict_sqlite_no_alts(self):
def test_convert_stardict_txt_1(self):
self.convert_stardict_txt(
"100-en-fa",
"100-en-fa-sd",
"100-en-fa-sd-v2",
"100-en-fa-sd-v2",
"1",
)

def test_convert_stardict_txt_mixed_types_1(self):
self.convert_stardict_txt(
"stardict-mixed-types-2",
"stardict-mixed-types-2.sd",
"stardict-mixed-types-2.sd",
"mixed-types-1",
syn=False,
)
Expand All @@ -268,6 +277,7 @@ def test_convert_stardict_txt_mixed_types_2(self):
self.convert_stardict_txt(
"stardict-mixed-types-2",
"stardict-mixed-types-2.sd",
"stardict-mixed-types-2.sd",
"mixed-types-1",
syn=False,
readOptions={"xdxf_to_html": False},
Expand All @@ -276,12 +286,14 @@ def test_convert_stardict_txt_mixed_types_2(self):
def test_convert_txt_stardict_general_1(self):
self.convert_txt_stardict(
"002-plain-html",
"002-plain-html.sd",
syn=False,
)

def test_convert_txt_stardict_general_2(self):
self.convert_txt_stardict(
"004-plain-html-alts",
"004-plain-html-alts.sd",
syn=True,
)

Expand Down

0 comments on commit 81f0fce

Please sign in to comment.