Bump version number to 2.4.2 to pick up the latest minor bug fixes.
[python/dscho.git] / Lib / test / test_htmllib.py
blobe283d1118fea2ed6f47b0db329b4413844a50207
1 import formatter
2 import htmllib
3 import unittest
5 from test import test_support
8 class AnchorCollector(htmllib.HTMLParser):
9 def __init__(self, *args, **kw):
10 self.__anchors = []
11 htmllib.HTMLParser.__init__(self, *args, **kw)
13 def get_anchor_info(self):
14 return self.__anchors
16 def anchor_bgn(self, *args):
17 self.__anchors.append(args)
20 class HTMLParserTestCase(unittest.TestCase):
21 def test_anchor_collection(self):
22 # See SF bug #467059.
23 parser = AnchorCollector(formatter.NullFormatter(), verbose=1)
24 parser.feed(
25 """<a href='http://foo.org/' name='splat'> </a>
26 <a href='http://www.python.org/'> </a>
27 <a name='frob'> </a>
28 """)
29 parser.close()
30 self.assertEquals(parser.get_anchor_info(),
31 [('http://foo.org/', 'splat', ''),
32 ('http://www.python.org/', '', ''),
33 ('', 'frob', ''),
37 def test_main():
38 test_support.run_unittest(HTMLParserTestCase)
41 if __name__ == "__main__":
42 test_main()