[Python-modules-commits] [python-odf] 47/118: Unittest for XMLGenerator Sample documents added
Wolfgang Borgert
debacle at moszumanska.debian.org
Fri Oct 3 21:27:21 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to reference refs/remotes/upstream/master
in repository python-odf.
commit 99b241939f4dab4bccd9aaf503698648a6c52975
Author: Søren Roug <soren.roug at eea.europa.eu>
Date: Sun Mar 15 10:33:03 2009 +0000
Unittest for XMLGenerator
Sample documents added
---
grammar/Makefile | 4 +-
odflint/odflint | 3 +
samples/Bluff Crag.odt | Bin 0 -> 2179532 bytes
samples/Electra.odt | Bin 0 -> 54147 bytes
samples/spreadsheet-with-macro.ods | Bin 0 -> 34426 bytes
setup.py | 3 +-
tests/testxmlgen.py | 114 +++++++++++++++++++++++++++++++++++++
7 files changed, 122 insertions(+), 2 deletions(-)
diff --git a/grammar/Makefile b/grammar/Makefile
index fb6bb32..7be29ce 100644
--- a/grammar/Makefile
+++ b/grammar/Makefile
@@ -24,7 +24,9 @@ allowed_attrs.py: simple-schema-7-22.rng simple-manifest-7-22.rng gen_allowed_at
python gen_allowed_attrs.py > allowed_attrs.py
clean:
- rm -f odf simple-schema-7-*.rng simple-manifest-7-*.rng required_attrs.py allowed_attrs.py allowed_children.py
+ rm -f odf simple-schema-7-*.rng simple-manifest-7-*.rng \
+ required_attrs.py allowed_attrs.py allowed_children.py allows_text.py \
+ grammarnew.py
odf:
ln -s ../odf
diff --git a/odflint/odflint b/odflint/odflint
index 25efa14..aaaab5a 100755
--- a/odflint/odflint
+++ b/odflint/odflint
@@ -38,6 +38,9 @@ extension_attributes = {
(STYLENS,u'section-properties'): (
(STYLENS,u'editable'),
),
+ (MANIFESTNS,u'file-entry'): (
+ (MANIFESTNS,u'version'),
+ ),
},
"OpenOffice.org" : {
(METANS,u'template'): (
diff --git a/samples/Bluff Crag.odt b/samples/Bluff Crag.odt
new file mode 100644
index 0000000..b50118e
Binary files /dev/null and b/samples/Bluff Crag.odt differ
diff --git a/samples/Electra.odt b/samples/Electra.odt
new file mode 100644
index 0000000..e4cfca9
Binary files /dev/null and b/samples/Electra.odt differ
diff --git a/samples/spreadsheet-with-macro.ods b/samples/spreadsheet-with-macro.ods
new file mode 100644
index 0000000..a60c09e
Binary files /dev/null and b/samples/spreadsheet-with-macro.ods differ
diff --git a/setup.py b/setup.py
index 97e8832..f061a63 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2006-2008 Søren Roug, European Environment Agency
+# Copyright (C) 2006-2009 Søren Roug, European Environment Agency
#
# This is free software. You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
@@ -75,6 +75,7 @@ understanding of data types.
In addition to the API, there are a few scripts:
+- csv2odf - Create OpenDocument spreadsheet from comma separated values
- mailodf - Email ODF file as HTML archive
- odf2xhtml - Convert ODF to (X)HTML
- odf2mht - Convert ODF to HTML archive
diff --git a/tests/testxmlgen.py b/tests/testxmlgen.py
new file mode 100644
index 0000000..d56ac0f
--- /dev/null
+++ b/tests/testxmlgen.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2009 Søren Roug, European Environment Agency
+#
+# This is free software. You may redistribute it under the terms
+# of the Apache license and the GNU General Public License Version
+# 2 or at your option any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Contributor(s):
+#
+
+import xml.sax, xml.sax.saxutils
+import StringIO
+import unittest
+
+class MyGen(xml.sax.saxutils.XMLGenerator):
+
+ def _qname(self, name):
+ """Builds a qualified name from a (ns_url, localname) pair"""
+ if name[0]:
+ if name[0] == u'http://www.w3.org/XML/1998/namespace':
+ return u'xml' + ":" + name[1]
+ # The name is in a non-empty namespace
+ prefix = self._current_context[name[0]]
+ if prefix:
+ # If it is not the default namespace, prepend the prefix
+ return prefix + ":" + name[1]
+ # Return the unqualified name
+ return name[1]
+
+class TestXMLGenerator(unittest.TestCase):
+
+ def test_xmlgenerator(self):
+ """ Test that the xml namespace is understood by XMLGenerator """
+ outfp = StringIO.StringIO()
+ c = xml.sax.saxutils.XMLGenerator(outfp,'utf-8')
+ parser = xml.sax.make_parser()
+ parser.setFeature(xml.sax.handler.feature_namespaces, 1)
+ parser.setContentHandler(c)
+ testcontent="""<?xml version="1.0"?>
+<a:greetings xmlns:a="http://example.com/ns" xmlns:xml="http://www.w3.org/XML/1998/namespace">
+ <a:greet xml:lang="en">Hello world</a:greet>
+</a:greetings>"""
+ parser.feed(testcontent)
+ parser.close()
+ expectedresult = """<?xml version="1.0" encoding="utf-8"?>
+<a:greetings xmlns:a="http://example.com/ns" xmlns:xml="http://www.w3.org/XML/1998/namespace">
+ <a:greet xml:lang="en">Hello world</a:greet>
+</a:greetings>"""
+ self.assertEqual( outfp.getvalue(), expectedresult)
+
+
+ def test_xmlgenerator_wo_ns(self):
+ """ Test that the missing xml namespace is understood by XMLGenerator """
+ outfp = StringIO.StringIO()
+ c = xml.sax.saxutils.XMLGenerator(outfp,'utf-8')
+ parser = xml.sax.make_parser()
+ parser.setFeature(xml.sax.handler.feature_namespaces, 1)
+ parser.setContentHandler(c)
+ testcontent="""<?xml version="1.0"?>
+<a:greetings xmlns:a="http://example.com/ns">
+ <a:greet xml:lang="en">Hello world</a:greet>
+</a:greetings>"""
+ self.assertRaises(KeyError, parser.feed, testcontent)
+
+ def test_myxml(self):
+ """ Test that my patch works """
+ outfp = StringIO.StringIO()
+ c = MyGen(outfp,'utf-8')
+ parser = xml.sax.make_parser()
+ parser.setFeature(xml.sax.handler.feature_namespaces, 1)
+ parser.setContentHandler(c)
+ testcontent="""<?xml version="1.0"?>
+<a:greetings xmlns:a="http://example.com/ns" xmlns:xml="http://www.w3.org/XML/1998/namespace">
+ <a:greet xml:lang="en">Hello world</a:greet>
+</a:greetings>"""
+ parser.feed(testcontent)
+ parser.close()
+ expectedresult = """<?xml version="1.0" encoding="utf-8"?>
+<a:greetings xmlns:a="http://example.com/ns" xmlns:xml="http://www.w3.org/XML/1998/namespace">
+ <a:greet xml:lang="en">Hello world</a:greet>
+</a:greetings>"""
+ self.assertEqual( outfp.getvalue(), expectedresult)
+
+ def test_myxml_wo_xml(self):
+ """ Test that my patch understands the missing xml namespace """
+ outfp = StringIO.StringIO()
+ c = MyGen(outfp,'utf-8')
+ parser = xml.sax.make_parser()
+ parser.setFeature(xml.sax.handler.feature_namespaces, 1)
+ parser.setContentHandler(c)
+ testcontent="""<?xml version="1.0"?>
+<a:greetings xmlns:a="http://example.com/ns" xmlns:xml="http://www.w3.org/XML/1998/namespace">
+ <a:greet xml:lang="en">Hello world</a:greet>
+</a:greetings>"""
+ parser.feed(testcontent)
+ parser.close()
+ expectedresult = """<?xml version="1.0" encoding="utf-8"?>
+<a:greetings xmlns:a="http://example.com/ns" xmlns:xml="http://www.w3.org/XML/1998/namespace">
+ <a:greet xml:lang="en">Hello world</a:greet>
+</a:greetings>"""
+ self.assertEqual( outfp.getvalue(), expectedresult)
+
+if __name__ == '__main__':
+ unittest.main()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-odf.git
More information about the Python-modules-commits
mailing list