~ubuntu-branches/ubuntu/lucid/thuban/lucid

« back to all changes in this revision

Viewing changes to test/test_xmlsupport.py

  • Committer: Bazaar Package Importer
  • Author(s): Silke Reimer
  • Date: 2004-01-28 12:47:34 UTC
  • Revision ID: james.westby@ubuntu.com-20040128124734-6xotwcqilok6ngut
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2003 by Intevation GmbH
 
2
# Authors:
 
3
# Bernhard Herzog <bh@intevation.de>
 
4
#
 
5
# This program is free software under the GPL (>=v2)
 
6
# Read the file COPYING coming with the software for details.
 
7
 
 
8
"""Test for the xmlsupport.py module
 
9
"""
 
10
 
 
11
__version__ = "$Revision: 1.4 $"
 
12
# $Source: /thubanrepository/thuban/test/test_xmlsupport.py,v $
 
13
# $Id: test_xmlsupport.py,v 1.4 2003/06/20 18:29:16 bh Exp $
 
14
 
 
15
import unittest
 
16
 
 
17
import xmlsupport
 
18
import support
 
19
 
 
20
class TestValidation(unittest.TestCase, xmlsupport.ValidationTest):
 
21
 
 
22
    def test_simple(self):
 
23
        """test xmlsupport validating valid XML
 
24
 
 
25
        The test succeeds if validate_data doesn't raise any exception
 
26
        """
 
27
        data = ('<?xml version="1.0" encoding="UTF-8"?>\n'
 
28
                '<!DOCTYPE session SYSTEM "thuban.dtd">\n'
 
29
                '<session title="empty session">\n</session>\n')
 
30
        self.validate_data(data)
 
31
 
 
32
    def test_invalid(self):
 
33
        """test xmlsupport validating invalid XML
 
34
 
 
35
        The test succeeds if validate_data raises an assertion error
 
36
        """
 
37
        data = ('<?xml version="1.0" encoding="UTF-8"?>\n'
 
38
                '<!DOCTYPE session SYSTEM "thuban.dtd">\n'
 
39
                '<session foo="bar">\n</session>\n')
 
40
        # only really run this test when pyRXP is available
 
41
        if xmlsupport.pyRXP is not None:
 
42
            self.assertRaises(AssertionError, self.validate_data, data)
 
43
 
 
44
 
 
45
 
 
46
class TestEventList(unittest.TestCase):
 
47
 
 
48
    """Test cases for sax_eventlist"""
 
49
 
 
50
    def test_even_list_simple(self):
 
51
        """Test sax_eventlist on very simple XML"""
 
52
        data = "\n".join(['<?xml version="1.0" encoding="UTF-8"?>'
 
53
                          '<!DOCTYPE session SYSTEM "thuban.dtd">'
 
54
                          '<session title="single map&amp;layer">'
 
55
                          '</session>'])
 
56
 
 
57
        self.assertEquals(xmlsupport.sax_eventlist(data = data),
 
58
                          [('start', (None, u'session'),
 
59
                            [((None, u'title'), u'single map&layer')]),
 
60
                           ('end', (None, u'session'))])
 
61
 
 
62
    def test_even_list_namespace(self):
 
63
        """Test sax_eventlist on XML with a default namespace"""
 
64
        data = "\n".join(['<?xml version="1.0" encoding="UTF-8"?>'
 
65
                          '<!DOCTYPE session SYSTEM "thuban.dtd">'
 
66
                          '<session title="single map&amp;layer"'
 
67
                            ' xmlns="http://example.com/example.dtd">'
 
68
                          '</session>'])
 
69
 
 
70
        self.assertEquals(xmlsupport.sax_eventlist(data = data),
 
71
                          [('start', (u'http://example.com/example.dtd',
 
72
                                      u'session'),
 
73
                            [((None, u'title'), u'single map&layer')]),
 
74
                           ('end', (u'http://example.com/example.dtd',
 
75
                                    u'session'))])
 
76
 
 
77
    def test_even_list_id_normalization(self):
 
78
        """Test sax_eventlist id normalization"""
 
79
        data1 = "\n".join(['<?xml version="1.0" encoding="UTF-8"?>'
 
80
                           '<!DOCTYPE session SYSTEM "thuban.dtd">'
 
81
                           '<session title="bla">'
 
82
                           '   <table id="foo"/>'
 
83
                           '   <tableref id="foo"/>'
 
84
                           '</session>'])
 
85
 
 
86
        data2 = "\n".join(['<?xml version="1.0" encoding="UTF-8"?>'
 
87
                           '<!DOCTYPE session SYSTEM "thuban.dtd">'
 
88
                           '<session title="bla">'
 
89
                           '   <table id="bar"/>'
 
90
                           '   <tableref id="bar"/>'
 
91
                           '</session>'])
 
92
        ids = [((None, "table"), (None, "id"))]
 
93
        idrefs = [((None, "tableref"), (None, "id"))]
 
94
        self.assertEquals(xmlsupport.sax_eventlist(data = data1, ids = ids,
 
95
                                                   idrefs = idrefs),
 
96
                          xmlsupport.sax_eventlist(data = data2, ids = ids,
 
97
                                                   idrefs = idrefs))
 
98
 
 
99
if __name__ == "__main__":
 
100
    # Fake the __file__ global because it's needed by a test
 
101
    import sys
 
102
    __file__ = sys.argv[0]
 
103
    support.run_tests()