blob: 0780bc95f3d14281a7cb2f1dd8e804eb8788233d [file] [log] [blame]
Guido van Rossum02505e41998-01-29 14:55:24 +00001'''Test module to thest the xmllib module.
2 Sjoerd Mullender
3'''
4
Guido van Rossum02505e41998-01-29 14:55:24 +00005testdoc = """\
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 -->
Fred Drakebabd7372001-05-22 20:22:06 +00009<?processing instructions are allowed in the same places as comments ?>
Guido van Rossum02505e41998-01-29 14:55:24 +000010<!DOCTYPE greeting [
11 <!ELEMENT greeting (#PCDATA)>
12]>
13<greeting>Hello, world!</greeting>
14"""
15
Martin v. Löwis9f1340b2004-05-02 20:37:13 +000016nsdoc = "<foo xmlns='URI' attr='val'/>"
17
Tim Petersa7c2b302002-04-11 20:18:40 +000018import warnings
19warnings.filterwarnings("ignore", ".* xmllib .* obsolete.*",
Tim Petersd3925062002-04-16 01:27:44 +000020 DeprecationWarning, r'xmllib$')
Tim Petersa7c2b302002-04-11 20:18:40 +000021
Barry Warsaw04f357c2002-07-23 19:04:11 +000022from test import test_support
Fred Drakebabd7372001-05-22 20:22:06 +000023import unittest
Guido van Rossum02505e41998-01-29 14:55:24 +000024import xmllib
Guido van Rossum02505e41998-01-29 14:55:24 +000025
Fred Drakebabd7372001-05-22 20:22:06 +000026class 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
Martin v. Löwis9f1340b2004-05-02 20:37:13 +000034 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
Fred Drakebabd7372001-05-22 20:22:06 +000046
Fred Drake2e2be372001-09-20 21:33:42 +000047def test_main():
48 test_support.run_unittest(XMLParserTestCase)
Fred Drake2e2be372001-09-20 21:33:42 +000049
50if __name__ == "__main__":
51 test_main()