File: test_grammar.py

package info (click to toggle)
python-odf 1.3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,356 kB
  • ctags: 1,902
  • sloc: python: 21,654; makefile: 352; sh: 10; xml: 2
file content (101 lines) | stat: -rw-r--r-- 4,678 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/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 *

class TestAllowedAtts(unittest.TestCase):
    def testNewAllowedAtts(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]
            if atts is None:
                assert insatts is None, "Element %s:%s should have unknown attributes" % element
            else:
                for attr in atts:
                    assert attr in insatts, "Attribute %s:%s not in installed grammar for %s:%s" % (attr + element)

    def testAllowedAtts(self):
        "Testing allowed attributes in grammar"
        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]
            if atts is None:
                assert newatts is None, "Element %s:%s should have unknown attributes" % element
            else:
                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 testRequiredAttsNew(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 for %s:%s" % (attr + element)

    def testRequiredAtts(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 for %s:%s" % (attr + element)

class TestAllowedChildren(unittest.TestCase):
    def testAllowedChildrenNew(self):
        "Testing allowed children in grammarnew"
        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 testAllowedChildren(self):
        "Testing allowed children in grammar"
        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)

class TestAllowsText(unittest.TestCase):
    def testAllowsTextNew(self):
        "Testing grammarnew keys"
        for element in grammarnew.allows_text:
            assert element in grammar.allows_text, "%s:%s not in installed grammar" % element

    def testAllowsText(self):
        for element in grammar.allows_text:
            assert element in grammarnew.allows_text, "%s:%s not in new grammar" % element

if __name__ == '__main__':
    unittest.main()