From 1433b5cb11a00a72e36c47ba3fafb5e46c6b0df8 Mon Sep 17 00:00:00 2001 From: Robert Lehmann Date: Tue, 29 Jun 2010 23:30:22 +0200 Subject: [PATCH] Test translation patching in vitro. --- tests/root/bom.po | 12 ++++++++++++ tests/test_build_gettext.py | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/root/bom.po diff --git a/tests/root/bom.po b/tests/root/bom.po new file mode 100644 index 000000000..61455f84f --- /dev/null +++ b/tests/root/bom.po @@ -0,0 +1,12 @@ +#, fuzzy +msgid "" +msgstr "" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "File with UTF-8 BOM" +msgstr "Datei mit UTF-8 BOM" + +msgid "This file has a UTF-8 \"BOM\"." +msgstr "This file has umlauts: äöü." diff --git a/tests/test_build_gettext.py b/tests/test_build_gettext.py index 09dc0adb6..ede092894 100644 --- a/tests/test_build_gettext.py +++ b/tests/test_build_gettext.py @@ -70,3 +70,30 @@ def test_gettext(app): @with_app(buildername='gettext') def test_all(app): app.builder.build_all() + +@with_app(buildername='text', + confoverrides={'language': 'xx', 'locale_dirs': ['.']}) +def test_patch(app): + app.builder.build(['bom']) + res = (app.outdir / 'bom.txt').text('utf-8') + assert res == u"Datei mit UTF-8 BOM\n\nThis file has umlauts: äöü.\n" + +def setup_patch(): + (test_root / 'xx' / 'LC_MESSAGES').makedirs() + try: + p = Popen(['msgfmt', test_root / 'bom.po', '-o', + test_root / 'xx' / 'LC_MESSAGES' / 'bom.mo'], + stdout=PIPE, stderr=PIPE) + except OSError: + return # most likely msgfmt was not found + else: + stdout, stderr = p.communicate() + if p.returncode != 0: + print stdout + print stderr + assert False, 'msgfmt exited with return code %s' % p.returncode + assert (test_root / 'xx' / 'LC_MESSAGES' / 'bom.mo').isfile(), 'msgfmt failed' +def teardown_patch(): + (test_root / 'xx').rmtree() +test_patch.setup = setup_patch +test_patch.teardown = teardown_patch