diff options
author | Claude Paroz <claude@2xlibre.net> | 2011-05-30 21:23:15 +0200 |
---|---|---|
committer | Claude Paroz <claude@2xlibre.net> | 2011-05-30 21:23:15 +0200 |
commit | f4635d084d93212af73221de5165c3fa92f834cd (patch) | |
tree | 8fad5f69efba99b1482d0b75dca4da38d488d28b | |
parent | 00a8df54545a66aa70c20ceecb19709ca0b811a7 (diff) | |
download | itstool-f4635d084d93212af73221de5165c3fa92f834cd.tar.gz |
Initial test infrastructure
-rw-r--r-- | tests/Translate1.ll.po | 35 | ||||
-rw-r--r-- | tests/Translate1.ll.xml | 39 | ||||
-rw-r--r-- | tests/Translate1.pot | 35 | ||||
-rw-r--r-- | tests/run_tests.py | 66 |
4 files changed, 175 insertions, 0 deletions
diff --git a/tests/Translate1.ll.po b/tests/Translate1.ll.po new file mode 100644 index 0000000..29cb646 --- /dev/null +++ b/tests/Translate1.ll.po @@ -0,0 +1,35 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2011-05-30 18:39+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/Translate1.xml:15(body/par) +msgid "Text with an image: <img alt=\"Image description\" src=\"img.png\"/>." +msgstr "Texte avec une image : <img alt=\"Description d'image\" src=\"img.png\"/>." + +#: tests/Translate1.xml:16(body/par) +msgid "This is the first paragraph. It has some <_:verbatim-1/>." +msgstr "C'est le premier paragraphe. Il contient du texte <_:verbatim-1/>." + +#: tests/Translate1.xml:21(封面/汇集) +msgid "The Lord of the Rings" +msgstr "Le Seigneur des Anneaux" + +#: tests/Translate1.xml:22(封面/标题) +msgid "The Return of the King" +msgstr "Le retour du Roi" + +#: tests/Translate1.xml:26(章节/头注) +msgid "Minas Tirith" +msgstr "Minas Tirith" + +#: tests/Translate1.xml:27(章节/段落识别) +msgid "<_:姓名-1/> looked out from the shelter of <_:姓名-2/>'s cloak." +msgstr "<_:姓名-1/> regarda depuis l'abri du manteau de <_:姓名-2/>." + diff --git a/tests/Translate1.ll.xml b/tests/Translate1.ll.xml new file mode 100644 index 0000000..878fc1a --- /dev/null +++ b/tests/Translate1.ll.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<myMetaDoc xmlns:cml="myChineseMakupLanguage"> + <head> + <its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0"> + <its:translateRule selector="//img/@alt" translate="yes"/> + <its:translateRule selector="//*/@title" translate="yes"/> + <its:translateRule selector="//verbatim" translate="no"/> + <its:translateRule selector="//verbatim/@*" translate="no"/> + <its:translateRule selector="//verbatim//*/@*" translate="no"/> + <its:withinTextRule selector="//img|//verbatim" withinText="yes"/> + </its:rules> + </head> + <body> + <par>Texte avec une image : <img alt="Description d'image" src="img.png"/>.</par> + <par id="100" title="Text">C'est le premier paragraphe. Il contient du texte <verbatim>un-translatable + code with an image: <img src="test.png" alt="Image description"/></verbatim>.</par> + <insert xmlns:z="myChineseMakupLanguage" xmlns:i="http://www.w3.org/2005/11/its"> + <z:书籍> + <z:封面> + <z:汇集>Le Seigneur des Anneaux</z:汇集> + <z:标题>Le retour du Roi</z:标题> + <z:作者>J.R.R. Tolkein</z:作者> + </z:封面> + <z:章节 数="1"> + <z:头注>Minas Tirith</z:头注> + <z:段落识别 id="A34B"><z:姓名>Pippin</z:姓名> regarda depuis l'abri du manteau de <z:姓名>Gandalf</z:姓名>.</z:段落识别> + </z:章节> + <z:躯> + <i:rules version="1.0" xmlns:cml="myChineseMakupLanguage"> + <i:translateRule selector="//cml:作者" translate="no"/> + <i:translateRule selector="//cml:姓名" translate="no"/> + <i:withinTextRule selector="//cml:姓名" withinText="yes"/> + </i:rules> + </z:躯> + </z:书籍> + </insert> + </body> +</myMetaDoc> +<!-- timestamp $Id: Translate1.xml,v 1.8 2007/02/02 17:36:15 ysavoure Exp $ --> diff --git a/tests/Translate1.pot b/tests/Translate1.pot new file mode 100644 index 0000000..312e0d6 --- /dev/null +++ b/tests/Translate1.pot @@ -0,0 +1,35 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2011-05-30 18:39+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/Translate1.xml:15(body/par) +msgid "Text with an image: <img alt=\"Image description\" src=\"img.png\"/>." +msgstr "" + +#: tests/Translate1.xml:16(body/par) +msgid "This is the first paragraph. It has some <_:verbatim-1/>." +msgstr "" + +#: tests/Translate1.xml:21(封面/汇集) +msgid "The Lord of the Rings" +msgstr "" + +#: tests/Translate1.xml:22(封面/标题) +msgid "The Return of the King" +msgstr "" + +#: tests/Translate1.xml:26(章节/头注) +msgid "Minas Tirith" +msgstr "" + +#: tests/Translate1.xml:27(章节/段落识别) +msgid "<_:姓名-1/> looked out from the shelter of <_:姓名-2/>'s cloak." +msgstr "" + diff --git a/tests/run_tests.py b/tests/run_tests.py new file mode 100644 index 0000000..f674b48 --- /dev/null +++ b/tests/run_tests.py @@ -0,0 +1,66 @@ +import os +import shutil +from subprocess import Popen, PIPE, call +import unittest + +TEST_DIR = os.path.dirname(os.path.abspath(__file__)) +ITSTOOL_DIR = os.path.dirname(TEST_DIR) + +class ItstoolTests(unittest.TestCase): + def tearDown(self): + for test_file in ('test.pot', 'test.mo', 'test.xml'): + path = os.path.join(TEST_DIR, test_file) + if os.path.exists(path): + os.remove(path) + + def run_command(self, cmd): + """ Helper method to run a shell command """ + pipe = Popen(cmd, shell=True, env=os.environ, stdin=None, stdout=PIPE, stderr=PIPE) + (output, errout) = pipe.communicate() + status = pipe.returncode + self.assertEqual(status, 0, errout or output) + return (status, output, errout) + + def assertFilesEqual(self, f1, f2): + options = "" + if f1.endswith(".po") or f1.endswith(".pot"): + options = "--ignore-matching-lines=^\\\"POT-Creation-Date" + result = self.run_command("diff -u %s %s %s" % (options, f1, f2)) + return self.assertEqual(result[1], "", result[1]) + + def test_unicode_markup(self): + result = self.run_command("cd %(dir)s && python itstool_test -o %(out)s %(in)s" % { + 'dir' : ITSTOOL_DIR, + 'out' : os.path.join('tests', "test.pot"), + 'in' : os.path.join('tests', 'Translate1.xml'), + }) + self.assertFilesEqual(os.path.join(TEST_DIR, "test.pot"), os.path.join(TEST_DIR, "Translate1.pot")) + + # Compile mo and merge + self.run_command("cd %(dir)s && msgfmt -o test.mo Translate1.ll.po" % {'dir': TEST_DIR}) + res = 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, "Translate1.xml"), + }) + self.assertFilesEqual(os.path.join(TEST_DIR, "test.xml"), os.path.join(TEST_DIR, "Translate1.ll.xml")) + + +class ITSTestRunner(unittest.TextTestRunner): + def run(self, test): + # Global setup + test_binary_path = os.path.join(ITSTOOL_DIR, "itstool_test") + shutil.copy(os.path.join(ITSTOOL_DIR, "itstool.in"), test_binary_path) + data_dir = os.path.join(ITSTOOL_DIR, "its") + call("sed -i -e 's/@DATADIR@/%s/' %s" % (data_dir.replace('/', '\/'), test_binary_path), shell=True) + + result = super(ITSTestRunner, self).run(test) + + os.remove(test_binary_path) + return result + + +if __name__ == '__main__': + unittest.main(testRunner=ITSTestRunner) + |