diff options
author | Claude Paroz <claude@2xlibre.net> | 2011-08-17 13:32:42 +0200 |
---|---|---|
committer | Claude Paroz <claude@2xlibre.net> | 2011-08-17 13:32:42 +0200 |
commit | 7e0739641507d92e1d2ec7e9b7f5e5c7c09a940a (patch) | |
tree | 5cdc640a4f0528b74c88a7235a4a9145263ff1d9 | |
parent | 1abdf1b0d83b37a9f298563e139c118c9a62629b (diff) | |
download | itstool-7e0739641507d92e1d2ec7e9b7f5e5c7c09a940a.tar.gz |
Catch XML errors in translated content
-rwxr-xr-x | itstool.in | 1 | ||||
-rw-r--r-- | tests/Translate3.ll.wrong.po | 19 | ||||
-rw-r--r-- | tests/run_tests.py | 24 |
3 files changed, 38 insertions, 6 deletions
@@ -654,6 +654,7 @@ class Document (object): if child.type == 'element': fix_node_ns(child, childnsdefs) fix_node_ns(node, {}) + self._check_errors() def translate_attrs(self, oldnode, newnode): trans_attrs = [attr for attr in xml_attr_iter(oldnode) if self._its_translate_nodes.get(attr, 'no') == 'yes'] diff --git a/tests/Translate3.ll.wrong.po b/tests/Translate3.ll.wrong.po new file mode 100644 index 0000000..a143f9c --- /dev/null +++ b/tests/Translate3.ll.wrong.po @@ -0,0 +1,19 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2011-05-31 21:23+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: tests/Translate3.xml:6(head/title) +msgid "The Life of a Simple Man" +msgstr "La vie d'un simple homme" + +#: tests/Translate3.xml:9(body/p) +msgid "Everything started when Zebulon discovered that he had a <_:span-1/> who was a serious baseball <_:span-2/>." +msgstr "Tout commença alors que Zebulon découvrit qu'il avait un <_:span-1> qui était un <_:span-2/> sérieux de baseball." + diff --git a/tests/run_tests.py b/tests/run_tests.py index d935b52..2d4793f 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -18,7 +18,7 @@ class ItstoolTests(unittest.TestCase): """ Helper method to run a shell command """ # Set stdout = sys.stdout to debug a subprocess if you set a breakpoint in it pipe = Popen(cmd, shell=True, env=os.environ, stdin=None, stdout=PIPE, stderr=PIPE) - (output, errout) = map(lambda x:x.decode(), pipe.communicate()) + (output, errout) = map(lambda x:x.decode('utf-8'), pipe.communicate()) status = pipe.returncode self.assertEqual(status, expected_status, errout or output) return {'status': status, 'output': output, 'errors': errout} @@ -44,19 +44,26 @@ class ItstoolTests(unittest.TestCase): self.assertFilesEqual(os.path.join(TEST_DIR, "test.pot"), os.path.join(TEST_DIR, reference_pot)) return result - def _test_translation_process(self, start_file): + def _test_translation_process(self, start_file, expected_status=0, po_file=None): start_file_base = os.path.splitext(start_file)[0] self._test_pot_generation(start_file) # Compile mo and merge - self.run_command("cd %(dir)s && msgfmt -o test.mo %(base)s.ll.po" % {'dir': TEST_DIR, 'base': start_file_base}) - res = self.run_command("cd %(dir)s && python itstool_test -m %(mo)s -o %(res)s %(src)s" % { + if po_file is None: + po_file = "%s.ll.po" % start_file_base + self.run_command("cd %(dir)s && msgfmt -o test.mo %(po_file)s" % {'dir': TEST_DIR, 'po_file': po_file}) + result = self.run_command("cd %(dir)s && python itstool_test -m %(mo)s -o %(res)s %(src)s" % { 'dir': ITSTOOL_DIR, 'mo' : os.path.join(TEST_DIR, "test.mo"), 'res': os.path.join(TEST_DIR, "test.xml"), 'src': os.path.join(TEST_DIR, start_file), - }) - self.assertFilesEqual(os.path.join(TEST_DIR, "test.xml"), os.path.join(TEST_DIR, "%s.ll.xml" % start_file_base)) + }, expected_status) + if (expected_status == 0): + self.assertFilesEqual( + os.path.join(TEST_DIR, "test.xml"), + os.path.join(TEST_DIR, "%s.ll.xml" % start_file_base) + ) + return result def test_locnotes(self): @@ -126,6 +133,11 @@ class ItstoolTests(unittest.TestCase): res = self._test_pot_generation('Malformed.xml', expected_status=1) self.assertTrue("libxml2.parserError" in res['errors']) + def test_bad_translation(self): + """ Test that bad XML syntax in translation generates a proper exception """ + res = self._test_translation_process('Translate3.xml', expected_status=1, po_file='Translate3.ll.wrong.po') + self.assertTrue("libxml2.parserError" in res['errors']) + class ITSTestRunner(unittest.TextTestRunner): def run(self, test): |