summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2011-06-01 13:45:51 +0200
committerClaude Paroz <claude@2xlibre.net>2011-06-01 14:27:31 +0200
commit480a2531c9b8ba0249f9326e8d043de309486e5b (patch)
treeb5172a477a73af29cbb9093f03b4484fcf7df98a
parent2ffe1d30ea1d5925a75955bc9b88c3d4c14b7b46 (diff)
downloaditstool-480a2531c9b8ba0249f9326e8d043de309486e5b.tar.gz
Add remaining tests
-rwxr-xr-xitstool.in5
-rw-r--r--tests/EX-locNotePointer-attribute-1.pot21
-rw-r--r--tests/EX-locNoteRefPointer-attribute-1.pot21
-rw-r--r--tests/LocNote1.pot25
-rw-r--r--tests/LocNote3.pot29
-rw-r--r--tests/LocNote4.pot30
-rw-r--r--tests/WithinText1.ll.po23
-rw-r--r--tests/WithinText1.ll.xml14
-rw-r--r--tests/WithinText1.pot23
-rw-r--r--tests/WithinText2.ll.po51
-rw-r--r--tests/WithinText2.ll.xml21
-rw-r--r--tests/WithinText2.pot51
-rw-r--r--tests/run_tests.py40
13 files changed, 350 insertions, 4 deletions
diff --git a/itstool.in b/itstool.in
index ccd139a..c6928fd 100755
--- a/itstool.in
+++ b/itstool.in
@@ -279,8 +279,7 @@ class Document (object):
hctxt.replaceEntities(1)
hctxt.parseDocument()
self._localrules.append(hctxt.doc().getRootElement())
- else:
- self._localrules.append(child)
+ self._localrules.append(child)
pre_process(child)
pre_process(self._doc)
self._msgs = messages
@@ -460,6 +459,8 @@ class Document (object):
xpath = self._doc.xpathNewContext()
reg_ns(xpath, rules)
for rule in xml_child_iter(rules):
+ if rule.type != 'element':
+ continue
if rule.nsDefs() is not None:
rule_xpath = self._doc.xpathNewContent()
reg_ns(rule_xpath, rule)
diff --git a/tests/EX-locNotePointer-attribute-1.pot b/tests/EX-locNotePointer-attribute-1.pot
new file mode 100644
index 0000000..cf4868f
--- /dev/null
+++ b/tests/EX-locNotePointer-attribute-1.pot
@@ -0,0 +1,21 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-01 10:24+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"
+
+#. Indicates that the resource file {0} could not be loaded.
+#: tests/EX-locNotePointer-attribute-1.xml:12(msg/data)
+msgid "Cannot find the file {0}."
+msgstr ""
+
+#. A division by 0 was going to be computed.
+#: tests/EX-locNotePointer-attribute-1.xml:16(msg/data)
+msgid "Invalid parameter."
+msgstr ""
+
diff --git a/tests/EX-locNoteRefPointer-attribute-1.pot b/tests/EX-locNoteRefPointer-attribute-1.pot
new file mode 100644
index 0000000..ba33be4
--- /dev/null
+++ b/tests/EX-locNoteRefPointer-attribute-1.pot
@@ -0,0 +1,21 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-01 10:31+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"
+
+#. SEE: Comments.html#FileNotFound
+#: tests/EX-locNoteRefPointer-attribute-1.xml:10(string/data)
+msgid "Cannot find the file {0}."
+msgstr ""
+
+#. SEE: Comments.html#DivByZero
+#: tests/EX-locNoteRefPointer-attribute-1.xml:13(string/data)
+msgid "Invalid parameter."
+msgstr ""
+
diff --git a/tests/LocNote1.pot b/tests/LocNote1.pot
new file mode 100644
index 0000000..0be16e3
--- /dev/null
+++ b/tests/LocNote1.pot
@@ -0,0 +1,25 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-01 09:53+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/LocNote1.xml:17(body/msg)
+msgid "This is a hippoptamus: <_:img-1/>."
+msgstr ""
+
+#: tests/LocNote1.xml:18(body/msg)
+msgid "This is an elephant: <_:img-1/>."
+msgstr ""
+
+#. The variable {0} has three possible values: 'printer', 'stacker' and
+#. 'stapler options'.
+#: tests/LocNote1.xml:19(body/msg)
+msgid "The {0} has been disabled."
+msgstr ""
+
diff --git a/tests/LocNote3.pot b/tests/LocNote3.pot
new file mode 100644
index 0000000..f8e3806
--- /dev/null
+++ b/tests/LocNote3.pot
@@ -0,0 +1,29 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-01 10:03+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/LocNote3.xml:5(msg/data)
+msgid "Host {0} cannot be found."
+msgstr ""
+
+#: tests/LocNote3.xml:8(msg/data)
+msgid "The connection with {0} has been lost."
+msgstr ""
+
+#. {0} is a filename
+#: tests/LocNote3.xml:11(msg/data)
+msgid "{0} not found."
+msgstr ""
+
+#. SEE: myLocNotes.htm#CannotLog
+#: tests/LocNote3.xml:14(msg/data)
+msgid "Cannot log with this username."
+msgstr ""
+
diff --git a/tests/LocNote4.pot b/tests/LocNote4.pot
new file mode 100644
index 0000000..421ea1f
--- /dev/null
+++ b/tests/LocNote4.pot
@@ -0,0 +1,30 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-01 10:12+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"
+
+#. SEE: http://en.wikipedia.org/wiki/Doppelganger
+#: tests/LocNote4.xml:5(span/span)
+msgid "doppelgänger"
+msgstr ""
+
+#: tests/LocNote4.xml:6(span/b)
+msgid "serious"
+msgstr ""
+
+#. SEE: http://en.wikipedia.org/wiki/Aficionado
+#: tests/LocNote4.xml:6(span/span)
+msgid "aficionado"
+msgstr ""
+
+#. If possible keep the non-English terms in the translated version too
+#: tests/LocNote4.xml:4(p/span)
+msgid "Everything started when Zebulon discovered that he had a <_:span-1/> who was a <_:b-2/> baseball <_:span-3/>."
+msgstr ""
+
diff --git a/tests/WithinText1.ll.po b/tests/WithinText1.ll.po
new file mode 100644
index 0000000..4135bf5
--- /dev/null
+++ b/tests/WithinText1.ll.po
@@ -0,0 +1,23 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-01 08:49+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/WithinText1.xml:9(body/p)
+msgid "This is a paragraph with <b>bold</b>, <i>italic</i>, and <u>underlined</u>."
+msgstr "Ceci est un paragraphe avec <b>gras</b>, <i>italique</i> et <u>souligné</u>."
+
+#: tests/WithinText1.xml:10(p/fn)
+msgid "This is the text of the footnote"
+msgstr "Voici le texte d'une note de pied de page"
+
+#: tests/WithinText1.xml:10(body/p)
+msgid "This is a paragraph with a footnote<_:fn-1/> at the middle."
+msgstr "Voici un paragraphe avec une note de pied de page<_:fn-1/> insérée au milieu."
+
diff --git a/tests/WithinText1.ll.xml b/tests/WithinText1.ll.xml
new file mode 100644
index 0000000..d956a50
--- /dev/null
+++ b/tests/WithinText1.ll.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<doc>
+ <head>
+ <its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
+ <its:withinTextRule withinText="yes" selector="//b|//u|//i"/>
+ <its:withinTextRule withinText="nested" selector="//fn"/>
+ </its:rules>
+ </head>
+ <body>
+ <p>Ceci est un paragraphe avec <b>gras</b>, <i>italique</i> et <u>souligné</u>.</p>
+ <p>Voici un paragraphe avec une note de pied de page<fn>Voici le texte d'une note de pied de page</fn> insérée au milieu.</p>
+ </body>
+ </doc>
+<!-- timestamp $Id: WithinText1.xml,v 1.3 2007/02/02 16:55:05 srahtz3 Exp $ -->
diff --git a/tests/WithinText1.pot b/tests/WithinText1.pot
new file mode 100644
index 0000000..de0b699
--- /dev/null
+++ b/tests/WithinText1.pot
@@ -0,0 +1,23 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-01 08:49+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/WithinText1.xml:9(body/p)
+msgid "This is a paragraph with <b>bold</b>, <i>italic</i>, and <u>underlined</u>."
+msgstr ""
+
+#: tests/WithinText1.xml:10(p/fn)
+msgid "This is the text of the footnote"
+msgstr ""
+
+#: tests/WithinText1.xml:10(body/p)
+msgid "This is a paragraph with a footnote<_:fn-1/> at the middle."
+msgstr ""
+
diff --git a/tests/WithinText2.ll.po b/tests/WithinText2.ll.po
new file mode 100644
index 0000000..865fbcc
--- /dev/null
+++ b/tests/WithinText2.ll.po
@@ -0,0 +1,51 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-01 09:34+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/WithinText2.xml:9(prolog/author)
+msgid "Zebulon Fairfield"
+msgstr "Zebulon Fairfield"
+
+#: tests/WithinText2.xml:10(prolog/version)
+msgid "version 12, revision 2 - 2006-08-14"
+msgstr "version 12, révision 2 - 14/08/2006"
+
+#: tests/WithinText2.xml:11(keywords/kw)
+msgid "horse"
+msgstr "cheval"
+
+#: tests/WithinText2.xml:11(keywords/kw)
+msgid "appaloosa"
+msgstr "appaloosa"
+
+#: tests/WithinText2.xml:12(prolog/storageKey)
+msgid "articles-6D272BA9-3B89CAD8"
+msgstr "articles-6D272BA9-3B89CAD8"
+
+#: tests/WithinText2.xml:16(section/title)
+msgid "Appaloosa"
+msgstr "Appaloosa"
+
+#: tests/WithinText2.xml:17(p/fnote)
+msgid "The name comes from \"Palouse horse\" in reference to the Palouse River in Northern Idaho."
+msgstr "Le nom provient de « cheval de Palouse » en référence à la rivière Palouse en Idaho du Nord."
+
+#: tests/WithinText2.xml:17(section/p)
+msgid "The Appaloosa<_:fnote-1/> are rugged horses originally breed by the <kw>Nez-Perce</kw> tribe in the US Northwest."
+msgstr "Les appaloosas<_:fnote-1/> sont de rudes chevaux élevés initialement par la tribu des <kw>Nez-Percés</kw> dans le Nord-ouest américain."
+
+#: tests/WithinText2.xml:20(section/p)
+msgid "They are often characterized by their spotted coats, as shown here: <img src=\"appaloosa.png\" alt=\"Appaloosa horses\"/>"
+msgstr "Ils sont souvent caractérisés par leur robe tachetée, comme sur cette image : <img src=\"appaloosa.png\" alt=\"Chevaux appaloosas\"/>"
+
+#: tests/WithinText2.xml:23(footer/p)
+msgid "Copyright: <em>Zebulon Inc.</em>"
+msgstr "Copyright : <em>Zebulon Inc.</em>"
+
diff --git a/tests/WithinText2.ll.xml b/tests/WithinText2.ll.xml
new file mode 100644
index 0000000..7fd9e1e
--- /dev/null
+++ b/tests/WithinText2.ll.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<myDocument xmlns="http://my.DocumentURI/" xml:lang="en">
+ <prolog>
+<its:rules xmlns:its="http://www.w3.org/2005/11/its" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:d="http://my.DocumentURI/" version="1.0" xlink:type="simple" xlink:href="WithinText2_LinkedRules.xml">
+ <its:withinTextRule selector="//d:keywords/d:kw" withinText="no"/>
+</its:rules>
+ <author>Zebulon Fairfield</author>
+ <version>version 12, révision 2 - 14/08/2006</version>
+ <keywords><kw>cheval</kw><kw>appaloosa</kw></keywords>
+ <storageKey>articles-6D272BA9-3B89CAD8</storageKey>
+ </prolog>
+ <content>
+ <section>
+ <title>Appaloosa</title>
+ <p>Les appaloosas<fnote>Le nom provient de « cheval de Palouse » en référence à la rivière Palouse en Idaho du Nord.</fnote> sont de rudes chevaux élevés initialement par la tribu des <kw>Nez-Percés</kw> dans le Nord-ouest américain.</p>
+ <p>Ils sont souvent caractérisés par leur robe tachetée, comme sur cette image : <img src="appaloosa.png" alt="Chevaux appaloosas"/></p>
+ </section>
+ <footer><p>Copyright : <em>Zebulon Inc.</em></p></footer>
+ </content>
+</myDocument>
+<!-- timestamp $Id: WithinText2.xml,v 1.8 2007/02/02 16:55:05 srahtz3 Exp $ -->
diff --git a/tests/WithinText2.pot b/tests/WithinText2.pot
new file mode 100644
index 0000000..0830499
--- /dev/null
+++ b/tests/WithinText2.pot
@@ -0,0 +1,51 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-01 09:34+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/WithinText2.xml:9(prolog/author)
+msgid "Zebulon Fairfield"
+msgstr ""
+
+#: tests/WithinText2.xml:10(prolog/version)
+msgid "version 12, revision 2 - 2006-08-14"
+msgstr ""
+
+#: tests/WithinText2.xml:11(keywords/kw)
+msgid "horse"
+msgstr ""
+
+#: tests/WithinText2.xml:11(keywords/kw)
+msgid "appaloosa"
+msgstr ""
+
+#: tests/WithinText2.xml:12(prolog/storageKey)
+msgid "articles-6D272BA9-3B89CAD8"
+msgstr ""
+
+#: tests/WithinText2.xml:16(section/title)
+msgid "Appaloosa"
+msgstr ""
+
+#: tests/WithinText2.xml:17(p/fnote)
+msgid "The name comes from \"Palouse horse\" in reference to the Palouse River in Northern Idaho."
+msgstr ""
+
+#: tests/WithinText2.xml:17(section/p)
+msgid "The Appaloosa<_:fnote-1/> are rugged horses originally breed by the <kw>Nez-Perce</kw> tribe in the US Northwest."
+msgstr ""
+
+#: tests/WithinText2.xml:20(section/p)
+msgid "They are often characterized by their spotted coats, as shown here: <img src=\"appaloosa.png\" alt=\"Appaloosa horses\"/>"
+msgstr ""
+
+#: tests/WithinText2.xml:23(footer/p)
+msgid "Copyright: <em>Zebulon Inc.</em>"
+msgstr ""
+
diff --git a/tests/run_tests.py b/tests/run_tests.py
index c14a26d..78d6e6a 100644
--- a/tests/run_tests.py
+++ b/tests/run_tests.py
@@ -1,6 +1,7 @@
import os
import shutil
from subprocess import Popen, PIPE, call
+import sys
import unittest
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -15,6 +16,7 @@ class ItstoolTests(unittest.TestCase):
def run_command(self, cmd):
""" 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) = pipe.communicate()
status = pipe.returncode
@@ -28,7 +30,7 @@ class ItstoolTests(unittest.TestCase):
result = self.run_command("diff -u %s %s %s" % (options, f1, f2))
return self.assertEqual(result[1], "", result[1])
- def _test_translation_process(self, start_file):
+ def _test_pot_generation(self, start_file, reference_pot=None):
start_file_base = os.path.splitext(start_file)[0]
result = self.run_command("cd %(dir)s && python itstool_test -o %(out)s %(in)s" % {
'dir' : ITSTOOL_DIR,
@@ -36,10 +38,15 @@ class ItstoolTests(unittest.TestCase):
'in' : os.path.join('tests', start_file),
})
# If a reference pot file is present, test the output with this file
- reference_pot = start_file_base + ".pot"
+ if reference_pot is None:
+ reference_pot = start_file_base + ".pot"
if os.path.exists(reference_pot):
self.assertFilesEqual(os.path.join(TEST_DIR, "test.pot"), os.path.join(TEST_DIR, reference_pot))
+ def _test_translation_process(self, start_file):
+ 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" % {
@@ -51,6 +58,28 @@ class ItstoolTests(unittest.TestCase):
self.assertFilesEqual(os.path.join(TEST_DIR, "test.xml"), os.path.join(TEST_DIR, "%s.ll.xml" % start_file_base))
+ def test_locnotes(self):
+ # FIXME: only the third note appears currently, as attribute extraction is not yet implemented
+ self._test_pot_generation('LocNote1.xml')
+
+ def test_locnotes_external(self):
+ # FIXME: only the third note appears currently, as attribute extraction is not yet implemented
+ self._test_pot_generation('LocNote2.xml', reference_pot='LocNote1.pot')
+
+ def test_locnotes_ontags(self):
+ self._test_pot_generation('LocNote3.xml')
+
+ def test_locnotes_onspan(self):
+ self._test_pot_generation('LocNote4.xml')
+
+ def test_locnotes_pointer(self):
+ self._test_pot_generation('EX-locNotePointer-attribute-1.xml')
+
+ def test_locnotes_refpointer(self):
+ self._test_pot_generation('EX-locNoteRefPointer-attribute-1.xml')
+
+ # FIXME: test EX-locNote-selector-2.xml when parent locNotes will propagate to children
+
def test_unicode_markup(self):
self._test_translation_process('Translate1.xml')
@@ -76,6 +105,13 @@ class ItstoolTests(unittest.TestCase):
def xx_test_attribute_selectable(self):
self._test_translation_process('TranslateGlobal.xml')
+ def test_withintext(self):
+ self._test_translation_process('WithinText1.xml')
+
+ def test_withintext_linkedrules(self):
+ self._test_translation_process('WithinText2.xml')
+
+
class ITSTestRunner(unittest.TextTestRunner):
def run(self, test):
# Global setup