blob: 620853d3ba55a652b87bbedb88895c5fe56bca6f [file] [log] [blame]
Fred Drake4e7cdb52001-10-04 20:05:10 +00001import formatter
2import htmllib
3import unittest
4
5import test_support
6
7
8class AnchorCollector(htmllib.HTMLParser):
9 def __init__(self, *args, **kw):
10 self.__anchors = []
11 htmllib.HTMLParser.__init__(self, *args, **kw)
12
13 def get_anchor_info(self):
14 return self.__anchors
15
16 def anchor_bgn(self, *args):
17 self.__anchors.append(args)
18
19
20class 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', ''),
34 ])
35
36
37def test_main():
38 test_support.run_unittest(HTMLParserTestCase)
39
40
41if __name__ == "__main__":
42 test_main()