Skip to content

Commit

Permalink
Added dummy translation in i18n_tool test
Browse files Browse the repository at this point in the history
  • Loading branch information
zenmonkeykstop committed Jun 2, 2021
1 parent 1b0007f commit 6bf33a8
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion securedrop/tests/test_i18n_tool.py
Expand Up @@ -14,6 +14,24 @@
from sh import sed, msginit, pybabel, git, touch


def dummy_translate(po):
buf = None
with io.open(po, "r") as in_file:
buf = in_file.readlines()

with io.open(po, "w") as out_file:
for line in buf:
if line.startswith("msgid "):
out_file.write(line)
idstr = line.split("msgid ", 1)
out_file.write("msgstr {}".format(idstr[1]))

elif line.startswith("msgstr "):
pass
else:
out_file.write(line)


class TestI18NTool(object):

def setup(self):
Expand Down Expand Up @@ -145,6 +163,10 @@ def test_translate_messages_l10n(self, tmpdir):
locale = 'en_US'
locale_dir = join(str(tmpdir), locale)
pybabel('init', '-i', messages_file, '-d', str(tmpdir), '-l', locale)

po_file = join(locale_dir, 'LC_MESSAGES/messages.po')
dummy_translate(po_file)

mo_file = join(locale_dir, 'LC_MESSAGES/messages.mo')
assert not exists(mo_file)
i18n_tool.I18NTool().main(args)
Expand Down Expand Up @@ -195,6 +217,10 @@ def test_translate_messages_compile_arg(self, tmpdir):
current_po_mtime = getmtime(po_file)
assert old_po_mtime < current_po_mtime

#
# Translation would occur here - let's fake it
dummy_translate(po_file)

#
# Compile but do not extract+update
#
Expand All @@ -207,7 +233,7 @@ def test_translate_messages_compile_arg(self, tmpdir):
'--sources', ",".join(source),
'--compile',
])
assert old_po_mtime == getmtime(po_file)
assert old_po_mtime < getmtime(po_file)
with io.open(mo_file, mode='rb') as fobj:
mo = fobj.read()
assert b'code hello i18n' in mo
Expand Down

0 comments on commit 6bf33a8

Please sign in to comment.