blob: 68b883a0e50f31403353b35220bdf3493dd7b13b [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
Barry Warsaw04f357c2002-07-23 19:04:11 +000018from test import test_support
Fred Drakebabd7372001-05-22 20:22:06 +000019import unittest
Ezio Melottia2d46532010-01-30 07:22:54 +000020# Silence Py3k warning
21xmllib = test_support.import_module('xmllib', deprecated=True)
Guido van Rossum02505e41998-01-29 14:55:24 +000022
Fred Drakebabd7372001-05-22 20:22:06 +000023class XMLParserTestCase(unittest.TestCase):
24
25 def test_simple(self):
26 parser = xmllib.XMLParser()
27 for c in testdoc:
28 parser.feed(c)
29 parser.close()
30
Martin v. Löwis9f1340b2004-05-02 20:37:13 +000031 def test_default_namespace(self):
32 class H(xmllib.XMLParser):
33 def unknown_starttag(self, name, attr):
34 self.name, self.attr = name, attr
35 h=H()
36 h.feed(nsdoc)
37 h.close()
38 # The default namespace applies to elements...
39 self.assertEquals(h.name, "URI foo")
40 # but not to attributes
41 self.assertEquals(h.attr, {'attr':'val'})
42
Fred Drakebabd7372001-05-22 20:22:06 +000043
Fred Drake2e2be372001-09-20 21:33:42 +000044def test_main():
45 test_support.run_unittest(XMLParserTestCase)
Fred Drake2e2be372001-09-20 21:33:42 +000046
47if __name__ == "__main__":
48 test_main()