[Python-modules-commits] [python-odf] 33/118: Added unit test

Wolfgang Borgert debacle at moszumanska.debian.org
Fri Oct 3 21:27:19 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 6227d810e7882fc4b6e31f56f107dd1669af70ef
Author: Søren Roug <soren.roug at eea.europa.eu>
Date:   Sun Jan 4 19:50:35 2009 +0000

    Added unit test
---
 grammar/gen_allowed_attrs.py | 23 +++++------
 grammar/test_grammar.py      | 90 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 13 deletions(-)

diff --git a/grammar/gen_allowed_attrs.py b/grammar/gen_allowed_attrs.py
index b4c85b7..ebc7d3b 100755
--- a/grammar/gen_allowed_attrs.py
+++ b/grammar/gen_allowed_attrs.py
@@ -20,11 +20,9 @@
 from xml.sax import make_parser,handler
 from xml.sax.xmlreader import InputSource
 import xml.sax.saxutils
-import sys
 
 RELAXNS=u"http://relaxng.org/ns/structure/1.0"
 
-elements = {}
 currdef = None
 currelement = None
 currnode = None
@@ -47,9 +45,10 @@ class Attribute(Node):
 #
 class S22RelaxParser(handler.ContentHandler):
 
-    def __init__(self):
+    def __init__(self, elements):
         self.data = []
         self.level = 0
+        self.elements = elements
 
     def text(self):
         return ''.join(self.data)
@@ -81,20 +80,18 @@ class S22RelaxParser(handler.ContentHandler):
             currnode.name = "__ANYNAME__"
         self.data = []
 
-def parse_rng(relaxfile):
-    content = file(relaxfile)
+if __name__ == "__main__":
+    elements = {}
     parser = make_parser()
     parser.setFeature(handler.feature_namespaces, 1)
-    parser.setContentHandler(S22RelaxParser())
+    parser.setContentHandler(S22RelaxParser(elements))
     parser.setErrorHandler(handler.ErrorHandler())
 
-    inpsrc = InputSource()
-    inpsrc.setByteStream(content)
-    parser.parse(inpsrc)
-
-
-if __name__ == "__main__":
-    parse_rng("simple-schema-7-22.rng")
+    for relaxfile in ["simple-manifest-7-22.rng","simple-schema-7-22.rng"]:
+        content = file(relaxfile)
+        inpsrc = InputSource()
+        inpsrc.setByteStream(content)
+        parser.parse(inpsrc)
 
     print "allowed_attributes = {"
 
diff --git a/grammar/test_grammar.py b/grammar/test_grammar.py
new file mode 100644
index 0000000..36d8112
--- /dev/null
+++ b/grammar/test_grammar.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2007 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 unittest
+from odf import grammar
+import grammarnew
+
+from odf.namespaces import *
+
+# Bug in simplification.xsl
+grammarnew.allowed_children[(STYLENS,u'chart-properties')] = (
+                        (CHARTNS,u'symbol-image'),
+                                )
+
+class TestAllowedAtts(unittest.TestCase):
+    def testGrammarNew(self):
+        "Testing grammarnew keys"
+        for element,atts in grammarnew.allowed_attributes.items():
+            assert element in grammar.allowed_attributes, "%s:%s not in installed grammar" % element
+            insatts = grammar.allowed_attributes[element]
+            for attr in atts:
+                assert attr in insatts, "Attribute %s:%s not in installed grammar for %s:%s" % (attr + element)
+
+    def testGrammar(self):
+        "Testing grammar keys"
+        for element, atts in grammar.allowed_attributes.items():
+            assert element in grammarnew.allowed_attributes, "%s:%s not in new grammar" % element
+            newatts = grammarnew.allowed_attributes[element]
+            for attr in atts:
+                assert attr in newatts, "Attribute %s:%s not in new grammar for %s:%s" % (attr + element)
+
+class TestRequiredAtts(unittest.TestCase):
+    def testGrammarNew(self):
+        "Testing grammarnew keys"
+        for element,atts in grammarnew.required_attributes.items():
+            assert element in grammar.required_attributes, "%s:%s not in installed grammar" % element
+            insatts = grammar.required_attributes[element]
+            for attr in atts:
+                assert attr in insatts, "Attribute %s:%s not in installed grammar" % attr
+
+    def testGrammar(self):
+        "Testing grammar keys"
+        for element, atts in grammar.required_attributes.items():
+            assert element in grammarnew.required_attributes, "%s:%s not in new grammar" % element
+            newatts = grammarnew.required_attributes[element]
+            for attr in atts:
+                assert attr in newatts, "Attribute %s:%s not in new grammar" % attr
+
+class TestAllowedChildren(unittest.TestCase):
+    def testGrammarNew(self):
+        "Testing grammarnew keys"
+        for element,atts in grammarnew.allowed_children.items():
+            assert element in grammar.allowed_children, "%s:%s not in installed grammar" % element
+            insatts = grammar.allowed_children[element]
+            if atts is None:
+                assert insatts is None, "Element %s:%s should have unknown children" % element
+            else:
+                for attr in atts:
+                    assert attr in insatts, "Element %s:%s not in installed grammar for %s:%s" % (attr + element)
+
+    def testGrammar(self):
+        "Testing grammar keys"
+        for element, atts in grammar.allowed_children.items():
+            assert element in grammarnew.allowed_children, "%s:%s not in new grammar" % element
+            newatts = grammarnew.allowed_children[element]
+            if atts is None:
+                assert newatts is None, "Element %s:%s should have unknown children" % element
+            else:
+                for attr in atts:
+                    assert attr in newatts, "Element %s:%s not in new grammar for %s:%s" % (attr + element)
+
+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