Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svarlang 01 #184

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
411 changes: 411 additions & 0 deletions fdisk/nls/de_utf8.txt

Large diffs are not rendered by default.

408 changes: 408 additions & 0 deletions fdisk/nls/en_utf8.txt

Large diffs are not rendered by default.

407 changes: 407 additions & 0 deletions fdisk/nls/es_utf8.txt

Large diffs are not rendered by default.

411 changes: 411 additions & 0 deletions fdisk/nls/fr_utf8.txt

Large diffs are not rendered by default.

408 changes: 408 additions & 0 deletions fdisk/nls/it_utf8.txt

Large diffs are not rendered by default.

405 changes: 405 additions & 0 deletions fdisk/nls/pl_utf8.txt

Large diffs are not rendered by default.

409 changes: 409 additions & 0 deletions fdisk/nls/tr_utf8.txt

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions kitten/nls/kittenc.fr

This file was deleted.

14 changes: 0 additions & 14 deletions kitten/nls/kittenc.tr

This file was deleted.

File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions kittenc/nls/kittenc.fr-UTF-8

This file was deleted.

File renamed without changes.
14 changes: 0 additions & 14 deletions kittenc/nls/kittenc.tr-UTF-8

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
102 changes: 73 additions & 29 deletions test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import codec_mazovia

PROJECTS = (
KITTEN_PROGS = (
"append",
"assign",
"blocek",
Expand All @@ -27,7 +27,6 @@
"fdhelper",
"fdi",
"fdimples",
"fdisk",
"fdi-x86",
"fdnet",
"fdnpkg",
Expand All @@ -40,6 +39,7 @@
"gcdrom",
"help-legacy",
"htmlhelp",
"kittenc",
"label",
"localize",
"md5sum",
Expand Down Expand Up @@ -74,6 +74,10 @@
"xdel",
)

SVARLANG_PROGS = ('fdisk',)

HELP = KITTEN_PROGS + SVARLANG_PROGS

LANGUAGES = {
"en": "CP437",
"br": "CP850", # Only CTMOUSE uses 'br' for Brazilian Portuguese
Expand Down Expand Up @@ -117,24 +121,21 @@
"""


class Kitten(unittest.TestCase):

top = Path('.')

def _dotest(self, tipo, prg, lng):

indir = self.top / prg / tipo
if not indir.is_dir():
self.skipTest("'%s' not found" % str(indir))
class Common(unittest.TestCase):

outdir = output / prg / tipo
def _dotest(self, tipo, prg, lng, indir):
outdir = output / prg / indir.name
outdir.mkdir(parents=True, exist_ok=True)

# Hack for Brazilian (.ptBR -> .ptb)
tgt = outdir / (prg + "." + lng[0:4].lower())

src_utf = indir / (prg + "." + lng + ".UTF-8")
src_cpg = indir / (prg + "." + lng)
src_utf = indir / (prg + "." + lng + ".UTF-8")
bad_utf = indir / (prg + "." + lng + "-UTF-8")
if bad_utf.exists():
msg = "non standard UTF-8 suffix ('%s')" % bad_utf.suffix
raise self.failureException(msg)

# Ensure UTF-8 source is valid if it exists
have_utf = False
Expand All @@ -150,7 +151,7 @@ def _dotest(self, tipo, prg, lng):
if have_utf:
# Convert to output codepade
try:
hdr = HDR if tipo == 'nls' else HDR.replace('#', ';')
hdr = HDR if tipo == 'kitten' else HDR.replace('#', ';')
tgt.write_text(hdr + txt, encoding=LANGUAGES[lng], newline='\r\n')
except UnicodeEncodeError as e:
msg = "invalid character for target codepage ('%s')" % e
Expand All @@ -177,29 +178,70 @@ def _dotest(self, tipo, prg, lng):
self.skipTest("'%s' not found" % lng)


def generate_kitten_tests():
def create_test(test):
def do_test(self):
self._dotest(*test)
class Svarlang(unittest.TestCase):

def _dotest(self, tipo, prg, lng, indir):
# Svarlang 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)

docstring = """%s (%s) [%s]""" % (test[0].capitalize(), test[1], test[2].upper())
setattr(do_test, '__doc__', docstring)
return do_test


def generate_help_tests():
# Insert each test into the testcase
for p in HELP:
for l in LANGUAGES.keys():
hlp = Path(p) / 'help'
if hlp.is_dir():
test = ('help', p, l, hlp)
setattr(Common, 'test_%s_%s_%s' % test[0:3], create_test(test))

docstring = """Kitten %s (%s) [%s]""" % (test[0].upper(), test[1], test[2].upper())
setattr(do_test, '__doc__', docstring)
return do_test

def generate_kitten_tests():
# Insert each test into the testcase
tests = []
for p in PROJECTS:
for p in KITTEN_PROGS:
for l in LANGUAGES.keys():
nls = Path(p) / 'nls'
if nls.is_dir():
tests.append(('nls', p, l))
test = ('kitten', p, l, nls)
setattr(Common, 'test_%s_%s_%s' % test[0:3], create_test(test))

hlp = Path(p) / 'help'
if hlp.is_dir():
tests.append(('help', p, l))

for test in tests:
setattr(Kitten, 'test_%s_%s_%s' % test, create_test(test))
def generate_svarlang_tests():
# Insert each test into the testcase
for p in SVARLANG_PROGS:
for l in LANGUAGES.keys():
nls = Path(p) / 'nls'
if nls.is_dir():
test = ('svarlang', p, l, nls)
setattr(Svarlang, 'test_%s_%s_%s' % test[0:3], create_test(test))


class MyTestResult(unittest.TextTestResult):
Expand All @@ -213,6 +255,8 @@ class MyTestRunner(unittest.TextTestRunner):


if __name__ == '__main__':
generate_help_tests()
generate_kitten_tests()
generate_svarlang_tests()

unittest.main(testRunner=MyTestRunner, verbosity=2)
File renamed without changes.