]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | '''Test module to thest the xmllib module.\r |
2 | Sjoerd Mullender\r | |
3 | '''\r | |
4 | \r | |
5 | testdoc = """\\r | |
6 | <?xml version="1.0" encoding="UTF-8" standalone='yes' ?>\r | |
7 | <!-- comments aren't allowed before the <?xml?> tag,\r | |
8 | but they are allowed before the <!DOCTYPE> tag -->\r | |
9 | <?processing instructions are allowed in the same places as comments ?>\r | |
10 | <!DOCTYPE greeting [\r | |
11 | <!ELEMENT greeting (#PCDATA)>\r | |
12 | ]>\r | |
13 | <greeting>Hello, world!</greeting>\r | |
14 | """\r | |
15 | \r | |
16 | nsdoc = "<foo xmlns='URI' attr='val'/>"\r | |
17 | \r | |
18 | from test import test_support\r | |
19 | import unittest\r | |
20 | # Silence Py3k warning\r | |
21 | xmllib = test_support.import_module('xmllib', deprecated=True)\r | |
22 | \r | |
23 | class XMLParserTestCase(unittest.TestCase):\r | |
24 | \r | |
25 | def test_simple(self):\r | |
26 | parser = xmllib.XMLParser()\r | |
27 | for c in testdoc:\r | |
28 | parser.feed(c)\r | |
29 | parser.close()\r | |
30 | \r | |
31 | def test_default_namespace(self):\r | |
32 | class H(xmllib.XMLParser):\r | |
33 | def unknown_starttag(self, name, attr):\r | |
34 | self.name, self.attr = name, attr\r | |
35 | h=H()\r | |
36 | h.feed(nsdoc)\r | |
37 | h.close()\r | |
38 | # The default namespace applies to elements...\r | |
39 | self.assertEqual(h.name, "URI foo")\r | |
40 | # but not to attributes\r | |
41 | self.assertEqual(h.attr, {'attr':'val'})\r | |
42 | \r | |
43 | \r | |
44 | def test_main():\r | |
45 | test_support.run_unittest(XMLParserTestCase)\r | |
46 | \r | |
47 | if __name__ == "__main__":\r | |
48 | test_main()\r |