1998-01-29 10:55:24 -04:00
|
|
|
'''Test module to thest the xmllib module.
|
|
|
|
Sjoerd Mullender
|
|
|
|
'''
|
|
|
|
|
|
|
|
testdoc = """\
|
|
|
|
<?xml version="1.0" encoding="UTF-8" standalone='yes' ?>
|
|
|
|
<!-- comments aren't allowed before the <?xml?> tag,
|
|
|
|
but they are allowed before the <!DOCTYPE> tag -->
|
2001-05-22 17:22:06 -03:00
|
|
|
<?processing instructions are allowed in the same places as comments ?>
|
1998-01-29 10:55:24 -04:00
|
|
|
<!DOCTYPE greeting [
|
|
|
|
<!ELEMENT greeting (#PCDATA)>
|
|
|
|
]>
|
|
|
|
<greeting>Hello, world!</greeting>
|
|
|
|
"""
|
|
|
|
|
2004-05-02 17:37:13 -03:00
|
|
|
nsdoc = "<foo xmlns='URI' attr='val'/>"
|
|
|
|
|
2002-07-23 16:04:11 -03:00
|
|
|
from test import test_support
|
2001-05-22 17:22:06 -03:00
|
|
|
import unittest
|
2010-01-30 03:22:54 -04:00
|
|
|
# Silence Py3k warning
|
|
|
|
xmllib = test_support.import_module('xmllib', deprecated=True)
|
1998-01-29 10:55:24 -04:00
|
|
|
|
2001-05-22 17:22:06 -03:00
|
|
|
class XMLParserTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
parser = xmllib.XMLParser()
|
|
|
|
for c in testdoc:
|
|
|
|
parser.feed(c)
|
|
|
|
parser.close()
|
|
|
|
|
2004-05-02 17:37:13 -03:00
|
|
|
def test_default_namespace(self):
|
|
|
|
class H(xmllib.XMLParser):
|
|
|
|
def unknown_starttag(self, name, attr):
|
|
|
|
self.name, self.attr = name, attr
|
|
|
|
h=H()
|
|
|
|
h.feed(nsdoc)
|
|
|
|
h.close()
|
|
|
|
# The default namespace applies to elements...
|
|
|
|
self.assertEquals(h.name, "URI foo")
|
|
|
|
# but not to attributes
|
|
|
|
self.assertEquals(h.attr, {'attr':'val'})
|
|
|
|
|
2001-05-22 17:22:06 -03:00
|
|
|
|
2001-09-20 18:33:42 -03:00
|
|
|
def test_main():
|
|
|
|
test_support.run_unittest(XMLParserTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|