From dd8ad680e7844615de8061e4ff7dde2c15a659ca Mon Sep 17 00:00:00 2001 From: Kevin O'Gorman Date: Wed, 2 Jun 2021 19:14:37 -0400 Subject: [PATCH] Added dummy translation in i18n_tool test --- securedrop/tests/test_i18n_tool.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/securedrop/tests/test_i18n_tool.py b/securedrop/tests/test_i18n_tool.py index a1228692b87..7fb89c9ec67 100644 --- a/securedrop/tests/test_i18n_tool.py +++ b/securedrop/tests/test_i18n_tool.py @@ -13,6 +13,23 @@ 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): @@ -139,18 +156,24 @@ def test_translate_messages_l10n(self, tmpdir): assert exists(messages_file) with io.open(messages_file, 'rb') as fobj: pot = fobj.read() + print(pot) assert b'code hello i18n' in pot assert b'template hello i18n' in pot 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) assert exists(mo_file) with io.open(mo_file, mode='rb') as fobj: mo = fobj.read() + print(mo) assert b'code hello i18n' in mo assert b'template hello i18n' in mo @@ -195,6 +218,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 # @@ -207,7 +234,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