Skip to content

Commit

Permalink
CI: Add Svardos UTF-8 > codepage conversion check
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbird committed Dec 31, 2023
1 parent 928429f commit 12412f4
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"fdhelper",
"fdi",
"fdimples",
"fdisk",
"fdi-x86",
"fdnet",
"fdnpkg",
Expand Down Expand Up @@ -75,7 +74,9 @@
"xdel",
)

HELP = KITTEN_PROGS
SVARDOS_PROGS = ('fdisk',)

HELP = KITTEN_PROGS + SVARDOS_PROGS

LANGUAGES = {
"en": "CP437",
Expand Down Expand Up @@ -177,6 +178,33 @@ def _dotest(self, tipo, prg, lng, indir):
self.skipTest("'%s' not found" % lng)


class Svardos(unittest.TestCase):

def _dotest(self, tipo, prg, lng, indir):
# SVARDOS input files are tested only for ability to convert from
# their UTF-8 to the target codepage, and any output is thrown away
# as user update of strings is not done.

src = indir / (lng + "_utf8.txt")
# Ensure UTF-8 source is valid if it exists
try:
txt = src.read_text(encoding="UTF-8")
except FileNotFoundError:
self.skipTest("'%s' not found" % lng)
except UnicodeDecodeError as e:
msg = "invalid character in UTF-8 ('%s')" % e
raise self.failureException(msg) from None

tgt = output / "target.txt"
try:
tgt.write_text(txt, encoding=LANGUAGES[lng], newline='\r\n')
except UnicodeEncodeError as e:
msg = "invalid character for target codepage ('%s')" % e
raise self.failureException(msg) from None

tgt.unlink()


def create_test(test):
def do_test(self):
self._dotest(*test)
Expand Down Expand Up @@ -206,6 +234,16 @@ def generate_kitten_tests():
setattr(Common, 'test_%s_%s_%s' % test[0:3], create_test(test))


def generate_svardos_tests():
# Insert each test into the testcase
for p in SVARDOS_PROGS:
for l in LANGUAGES.keys():
nls = Path(p) / 'nls'
if nls.is_dir():
test = ('svardos', p, l, nls)
setattr(Svardos, 'test_%s_%s_%s' % test[0:3], create_test(test))


class MyTestResult(unittest.TextTestResult):

def getDescription(self, test):
Expand All @@ -219,5 +257,6 @@ class MyTestRunner(unittest.TextTestRunner):
if __name__ == '__main__':
generate_help_tests()
generate_kitten_tests()
generate_svardos_tests()

unittest.main(testRunner=MyTestRunner, verbosity=2)

0 comments on commit 12412f4

Please sign in to comment.