annotate Lib/test/test_htmlparser.py @ 19283:b865cd5c1925 legacy-trunk

Added comments before recently added/assigned slots in the type object, so the backward compatibility issues will be easier to understand. I only added comments indicating additions and assignments back to Python 2.0.
author Fred Drake <fdrake@acm.org>
date Wed, 15 Aug 2001 18:32:33 +0000
parents ba9e4f55133f
children c403af003884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 """Tests for HTMLParser.py."""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3 import HTMLParser
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4 import sys
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 import test_support
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 import unittest
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9 class EventCollector(HTMLParser.HTMLParser):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 def __init__(self):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 self.events = []
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13 self.append = self.events.append
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14 HTMLParser.HTMLParser.__init__(self)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 def get_events(self):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 # Normalize the list of events so that buffer artefacts don't
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 # separate runs of contiguous characters.
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19 L = []
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
20 prevtype = None
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21 for event in self.events:
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 type = event[0]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23 if type == prevtype == "data":
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 L[-1] = ("data", L[-1][1] + event[1])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 else:
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26 L.append(event)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 prevtype = type
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 self.events = L
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 return L
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31 # structure markup
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33 def handle_starttag(self, tag, attrs):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34 self.append(("starttag", tag, attrs))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
35
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 def handle_startendtag(self, tag, attrs):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37 self.append(("startendtag", tag, attrs))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
38
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 def handle_endtag(self, tag):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 self.append(("endtag", tag))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 # all other markup
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44 def handle_comment(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 self.append(("comment", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47 def handle_charref(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48 self.append(("charref", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50 def handle_data(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 self.append(("data", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53 def handle_decl(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
54 self.append(("decl", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
55
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
56 def handle_entityref(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
57 self.append(("entityref", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
58
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59 def handle_pi(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
60 self.append(("pi", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
61
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
62
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
63 class EventCollectorExtra(EventCollector):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
64
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
65 def handle_starttag(self, tag, attrs):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
66 EventCollector.handle_starttag(self, tag, attrs)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67 self.append(("starttag_text", self.get_starttag_text()))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
69
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
70 class TestCaseBase(unittest.TestCase):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
71
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
72 # Constant pieces of source and events
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
73 prologue = ""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
74 epilogue = ""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
75 initial_events = []
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
76 final_events = []
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
77
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
78 def _run_check(self, source, events, collector=EventCollector):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
79 parser = collector()
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
80 parser.feed(self.prologue)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
81 for s in source:
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
82 parser.feed(s)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
83 for c in self.epilogue:
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
84 parser.feed(c)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
85 parser.close()
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
86 self.assert_(parser.get_events() ==
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
87 self.initial_events + events + self.final_events,
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
88 parser.get_events())
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
89
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
90 def _run_check_extra(self, source, events):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
91 self._run_check(source, events, EventCollectorExtra)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
92
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
93 def _parse_error(self, source):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
94 def parse(source=source):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
95 parser = HTMLParser.HTMLParser()
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
96 parser.feed(source)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
97 parser.close()
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
98 self.assertRaises(HTMLParser.HTMLParseError, parse)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
99
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
100
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
101 class HTMLParserTestCase(TestCaseBase):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
102
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
103 def test_processing_instruction_only(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
104 self._run_check("<?processing instruction>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
105 ("pi", "processing instruction"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
106 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
107
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
108 def test_simple_html(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
109 self._run_check("""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
110 <!DOCTYPE html PUBLIC 'foo'>
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
111 <HTML>&entity;&#32;
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
112 <!--comment1a
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
113 -></foo><bar>&lt;<?pi?></foo<bar
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
114 comment1b-->
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
115 <Img sRc='Bar' isMAP>sample
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
116 text
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
117 &#x201C;
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
118 <!--comment2a-- --comment2b-->
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
119 </Html>
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
120 """, [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
121 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
122 ("decl", "DOCTYPE html PUBLIC 'foo'"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
123 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
124 ("starttag", "html", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
125 ("entityref", "entity"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
126 ("charref", "32"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
127 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
128 ("comment", "comment1a\n-></foo><bar>&lt;<?pi?></foo<bar\ncomment1b"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
129 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
130 ("starttag", "img", [("src", "Bar"), ("ismap", None)]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
131 ("data", "sample\ntext\n"),
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
132 ("charref", "x201C"),
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
133 ("data", "\n"),
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
134 ("comment", "comment2a-- --comment2b"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
135 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
136 ("endtag", "html"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
137 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
138 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
139
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
140 def test_bad_nesting(self):
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
141 # Strangely, this *is* supposed to test that overlapping
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
142 # elements are allowed. HTMLParser is more geared toward
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
143 # lexing the input that parsing the structure.
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
144 self._run_check("<a><b></a></b>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
145 ("starttag", "a", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
146 ("starttag", "b", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
147 ("endtag", "a"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
148 ("endtag", "b"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
149 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
150
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
151 def test_attr_syntax(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
152 output = [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
153 ("starttag", "a", [("b", "v"), ("c", "v"), ("d", "v"), ("e", None)])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
154 ]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
155 self._run_check("""<a b='v' c="v" d=v e>""", output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
156 self._run_check("""<a b = 'v' c = "v" d = v e>""", output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
157 self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
158 self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
159
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
160 def test_attr_values(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
161 self._run_check("""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""",
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
162 [("starttag", "a", [("b", "xxx\n\txxx"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
163 ("c", "yyy\t\nyyy"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
164 ("d", "\txyz\n")])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
165 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
166 self._run_check("""<a b='' c="">""", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
167 ("starttag", "a", [("b", ""), ("c", "")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
168 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
169
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
170 def test_attr_entity_replacement(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
171 self._run_check("""<a b='&amp;&gt;&lt;&quot;&apos;'>""", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
172 ("starttag", "a", [("b", "&><\"'")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
173 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
174
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
175 def test_attr_funky_names(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
176 self._run_check("""<a a.b='v' c:d=v e-f=v>""", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
177 ("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
178 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
179
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
180 def test_starttag_end_boundary(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
181 self._run_check("""<a b='<'>""", [("starttag", "a", [("b", "<")])])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
182 self._run_check("""<a b='>'>""", [("starttag", "a", [("b", ">")])])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
183
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
184 def test_buffer_artefacts(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
185 output = [("starttag", "a", [("b", "<")])]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
186 self._run_check(["<a b='<'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
187 self._run_check(["<a ", "b='<'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
188 self._run_check(["<a b", "='<'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
189 self._run_check(["<a b=", "'<'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
190 self._run_check(["<a b='<", "'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
191 self._run_check(["<a b='<'", ">"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
192
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
193 output = [("starttag", "a", [("b", ">")])]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
194 self._run_check(["<a b='>'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
195 self._run_check(["<a ", "b='>'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
196 self._run_check(["<a b", "='>'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
197 self._run_check(["<a b=", "'>'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
198 self._run_check(["<a b='>", "'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
199 self._run_check(["<a b='>'", ">"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
200
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
201 def test_starttag_junk_chars(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
202 self._parse_error("<")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
203 self._parse_error("<>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
204 self._parse_error("</>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
205 self._parse_error("</$>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
206 self._parse_error("</")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
207 self._parse_error("</a")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
208 self._parse_error("<a<a>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
209 self._parse_error("</a<a>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
210 self._parse_error("<$")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
211 self._parse_error("<$>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
212 self._parse_error("<!")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
213 self._parse_error("<a $>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
214 self._parse_error("<a")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
215 self._parse_error("<a foo='bar'")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
216 self._parse_error("<a foo='bar")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
217 self._parse_error("<a foo='>'")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
218 self._parse_error("<a foo='>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
219 self._parse_error("<a foo=>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
220
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
221 def test_declaration_junk_chars(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
222 self._parse_error("<!DOCTYPE foo $ >")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
223
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
224 def test_startendtag(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
225 self._run_check("<p/>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
226 ("startendtag", "p", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
227 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
228 self._run_check("<p></p>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
229 ("starttag", "p", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
230 ("endtag", "p"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
231 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
232 self._run_check("<p><img src='foo' /></p>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
233 ("starttag", "p", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
234 ("startendtag", "img", [("src", "foo")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
235 ("endtag", "p"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
236 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
237
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
238 def test_get_starttag_text(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
239 s = """<foo:bar \n one="1"\ttwo=2 >"""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
240 self._run_check_extra(s, [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
241 ("starttag", "foo:bar", [("one", "1"), ("two", "2")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
242 ("starttag_text", s)])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
243
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
244 def test_cdata_content(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
245 s = """<script> <!-- not a comment --> &not-an-entity-ref; </script>"""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
246 self._run_check(s, [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
247 ("starttag", "script", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
248 ("data", " <!-- not a comment --> &not-an-entity-ref; "),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
249 ("endtag", "script"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
250 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
251 s = """<script> <not a='start tag'> </script>"""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
252 self._run_check(s, [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
253 ("starttag", "script", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
254 ("data", " <not a='start tag'> "),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
255 ("endtag", "script"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
256 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
257
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
258
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
259 test_support.run_unittest(HTMLParserTestCase)