Home | History | Annotate | Download | only in test
      1 '''Test module to thest the xmllib module.
      2    Sjoerd Mullender
      3 '''
      4 
      5 testdoc = """\
      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 -->
      9 <?processing instructions are allowed in the same places as comments ?>
     10 <!DOCTYPE greeting [
     11   <!ELEMENT greeting (#PCDATA)>
     12 ]>
     13 <greeting>Hello, world!</greeting>
     14 """
     15 
     16 nsdoc = "<foo xmlns='URI' attr='val'/>"
     17 
     18 from test import test_support
     19 import unittest
     20 # Silence Py3k warning
     21 xmllib = test_support.import_module('xmllib', deprecated=True)
     22 
     23 class 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 
     31     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.assertEqual(h.name, "URI foo")
     40         # but not to attributes
     41         self.assertEqual(h.attr, {'attr':'val'})
     42 
     43 
     44 def test_main():
     45     test_support.run_unittest(XMLParserTestCase)
     46 
     47 if __name__ == "__main__":
     48     test_main()
     49