PyXR

c:\python24\lib \ test \ test_htmllib.py



0001 import formatter
0002 import htmllib
0003 import unittest
0004 
0005 from test import test_support
0006 
0007 
0008 class AnchorCollector(htmllib.HTMLParser):
0009     def __init__(self, *args, **kw):
0010         self.__anchors = []
0011         htmllib.HTMLParser.__init__(self, *args, **kw)
0012 
0013     def get_anchor_info(self):
0014         return self.__anchors
0015 
0016     def anchor_bgn(self, *args):
0017         self.__anchors.append(args)
0018 
0019 class DeclCollector(htmllib.HTMLParser):
0020     def __init__(self, *args, **kw):
0021         self.__decls = []
0022         htmllib.HTMLParser.__init__(self, *args, **kw)
0023 
0024     def get_decl_info(self):
0025         return self.__decls
0026 
0027     def unknown_decl(self, data):
0028         self.__decls.append(data)
0029 
0030 
0031 class HTMLParserTestCase(unittest.TestCase):
0032     def test_anchor_collection(self):
0033         # See SF bug #467059.
0034         parser = AnchorCollector(formatter.NullFormatter(), verbose=1)
0035         parser.feed(
0036             """<a href='http://foo.org/' name='splat'> </a>
0037             <a href='http://www.python.org/'> </a>
0038             <a name='frob'> </a>
0039             """)
0040         parser.close()
0041         self.assertEquals(parser.get_anchor_info(),
0042                           [('http://foo.org/', 'splat', ''),
0043                            ('http://www.python.org/', '', ''),
0044                            ('', 'frob', ''),
0045                            ])
0046 
0047     def test_decl_collection(self):
0048         # See SF patch #545300
0049         parser = DeclCollector(formatter.NullFormatter(), verbose=1)
0050         parser.feed(
0051             """<html>
0052             <body>
0053             hallo
0054             <![if !supportEmptyParas]>&nbsp;<![endif]>
0055             </body>
0056             </html>
0057             """)
0058         parser.close()
0059         self.assertEquals(parser.get_decl_info(),
0060                           ["if !supportEmptyParas",
0061                            "endif"
0062                            ])
0063 
0064 def test_main():
0065     test_support.run_unittest(HTMLParserTestCase)
0066 
0067 
0068 if __name__ == "__main__":
0069     test_main()
0070 

Generated by PyXR 0.9.4
SourceForge.net Logo