PageRenderTime 27ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Lib/test/test_xmllib.py

http://unladen-swallow.googlecode.com/
Python | 51 lines | 47 code | 1 blank | 3 comment | 0 complexity | 558bbf2b5fd2450c49bbea99fce3c69f MD5 | raw file
 1'''Test module to thest the xmllib module.
 2   Sjoerd Mullender
 3'''
 4
 5testdoc = """\
 6<?xml version="1.0" encoding="UTF-8" standalone='yes' ?>
 7<!-- comments aren't allowed before the <?xml?> tag,
 8     but they are allowed before the <!DOCTYPE> tag -->
 9<?processing instructions are allowed in the same places as comments ?>
10<!DOCTYPE greeting [
11  <!ELEMENT greeting (#PCDATA)>
12]>
13<greeting>Hello, world!</greeting>
14"""
15
16nsdoc = "<foo xmlns='URI' attr='val'/>"
17
18import warnings
19warnings.filterwarnings("ignore", ".* xmllib .* obsolete.*",
20                        DeprecationWarning, r'xmllib$')
21
22from test import test_support
23import unittest
24import xmllib
25
26class XMLParserTestCase(unittest.TestCase):
27
28    def test_simple(self):
29        parser = xmllib.XMLParser()
30        for c in testdoc:
31            parser.feed(c)
32        parser.close()
33
34    def test_default_namespace(self):
35        class H(xmllib.XMLParser):
36            def unknown_starttag(self, name, attr):
37                self.name, self.attr = name, attr
38        h=H()
39        h.feed(nsdoc)
40        h.close()
41        # The default namespace applies to elements...
42        self.assertEquals(h.name, "URI foo")
43        # but not to attributes
44        self.assertEquals(h.attr, {'attr':'val'})
45
46
47def test_main():
48    test_support.run_unittest(XMLParserTestCase)
49
50if __name__ == "__main__":
51    test_main()