0001 '''Test module to thest the xmllib module. 0002 Sjoerd Mullender 0003 ''' 0004 0005 testdoc = """\ 0006 <?xml version="1.0" encoding="UTF-8" standalone='yes' ?> 0007 <!-- comments aren't allowed before the <?xml?> tag, 0008 but they are allowed before the <!DOCTYPE> tag --> 0009 <?processing instructions are allowed in the same places as comments ?> 0010 <!DOCTYPE greeting [ 0011 <!ELEMENT greeting (#PCDATA)> 0012 ]> 0013 <greeting>Hello, world!</greeting> 0014 """ 0015 0016 nsdoc = "<foo xmlns='URI' attr='val'/>" 0017 0018 import warnings 0019 warnings.filterwarnings("ignore", ".* xmllib .* obsolete.*", 0020 DeprecationWarning, r'xmllib$') 0021 0022 from test import test_support 0023 import unittest 0024 import xmllib 0025 0026 class XMLParserTestCase(unittest.TestCase): 0027 0028 def test_simple(self): 0029 parser = xmllib.XMLParser() 0030 for c in testdoc: 0031 parser.feed(c) 0032 parser.close() 0033 0034 def test_default_namespace(self): 0035 class H(xmllib.XMLParser): 0036 def unknown_starttag(self, name, attr): 0037 self.name, self.attr = name, attr 0038 h=H() 0039 h.feed(nsdoc) 0040 h.close() 0041 # The default namespace applies to elements... 0042 self.assertEquals(h.name, "URI foo") 0043 # but not to attributes 0044 self.assertEquals(h.attr, {'attr':'val'}) 0045 0046 0047 def test_main(): 0048 test_support.run_unittest(XMLParserTestCase) 0049 0050 if __name__ == "__main__": 0051 test_main() 0052
Generated by PyXR 0.9.4