annotate Lib/test/test_htmlparser.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents e592472d55a3
children aa0d2d51fbde
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
19410
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
4 import pprint
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 import sys
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 import test_support
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 import unittest
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
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10 class EventCollector(HTMLParser.HTMLParser):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 def __init__(self):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13 self.events = []
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14 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
15 HTMLParser.HTMLParser.__init__(self)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 def get_events(self):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 # 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
19 # 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
20 L = []
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21 prevtype = None
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 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
23 type = event[0]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 if type == prevtype == "data":
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 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
26 else:
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 L.append(event)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 prevtype = type
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 self.events = L
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30 return L
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32 # structure markup
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34 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
35 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
36
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37 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
38 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
39
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 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
41 self.append(("endtag", tag))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43 # all other markup
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 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
46 self.append(("comment", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48 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
49 self.append(("charref", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 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
52 self.append(("data", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
54 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
55 self.append(("decl", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
56
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
57 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
58 self.append(("entityref", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
60 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
61 self.append(("pi", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
62
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
63 def unknown_decl(self, decl):
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
64 self.append(("unknown decl", decl))
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
65
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
66
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67 class EventCollectorExtra(EventCollector):
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 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
70 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
71 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
72
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
73
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
74 class TestCaseBase(unittest.TestCase):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
75
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
76 def _run_check(self, source, expected_events, collector=EventCollector):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
77 parser = collector()
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
78 for s in source:
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
79 parser.feed(s)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
80 parser.close()
19410
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
81 events = parser.get_events()
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
82 if events != expected_events:
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
83 self.fail("received events did not match expected events\n"
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
84 "Expected:\n" + pprint.pformat(expected_events) +
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
85 "\nReceived:\n" + pprint.pformat(events))
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
86
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
87 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
88 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
89
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
90 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
91 def parse(source=source):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
92 parser = HTMLParser.HTMLParser()
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
93 parser.feed(source)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
94 parser.close()
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
95 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
96
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
97
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
98 class HTMLParserTestCase(TestCaseBase):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
99
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
100 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
101 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
102 ("pi", "processing instruction"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
103 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
104
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
105 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
106 self._run_check("""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
107 <!DOCTYPE html PUBLIC 'foo'>
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
108 <HTML>&entity;&#32;
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
109 <!--comment1a
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
110 -></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
111 comment1b-->
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
112 <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
113 text
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
114 &#x201C;
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
115 <!--comment2a-- --comment2b-->
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
116 </Html>
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
117 """, [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
118 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
119 ("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
120 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
121 ("starttag", "html", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
122 ("entityref", "entity"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
123 ("charref", "32"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
124 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
125 ("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
126 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
127 ("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
128 ("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
129 ("charref", "x201C"),
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
130 ("data", "\n"),
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
131 ("comment", "comment2a-- --comment2b"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
132 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
133 ("endtag", "html"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
134 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
135 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
136
21157
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
137 def test_unclosed_entityref(self):
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
138 self._run_check("&entityref foo", [
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
139 ("entityref", "entityref"),
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
140 ("data", " foo"),
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
141 ])
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
142
19410
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
143 def test_doctype_decl(self):
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
144 inside = """\
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
145 DOCTYPE html [
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
146 <!ELEMENT html - O EMPTY>
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
147 <!ATTLIST html
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
148 version CDATA #IMPLIED
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
149 profile CDATA 'DublinCore'>
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
150 <!NOTATION datatype SYSTEM 'http://xml.python.org/notations/python-module'>
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
151 <!ENTITY myEntity 'internal parsed entity'>
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
152 <!ENTITY anEntity SYSTEM 'http://xml.python.org/entities/something.xml'>
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
153 <!ENTITY % paramEntity 'name|name|name'>
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
154 %paramEntity;
19410
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
155 <!-- comment -->
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
156 ]"""
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
157 self._run_check("<!%s>" % inside, [
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
158 ("decl", inside),
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
159 ])
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
160
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
161 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
162 # 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
163 # 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
164 # 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
165 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
166 ("starttag", "a", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
167 ("starttag", "b", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
168 ("endtag", "a"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
169 ("endtag", "b"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
170 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
171
19410
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
172 def test_bare_ampersands(self):
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
173 self._run_check("this text & contains & ampersands &", [
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
174 ("data", "this text & contains & ampersands &"),
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
175 ])
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
176
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
177 def test_bare_pointy_brackets(self):
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
178 self._run_check("this < text > contains < bare>pointy< brackets", [
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
179 ("data", "this < text > contains < bare>pointy< brackets"),
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
180 ])
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
181
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
182 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
183 output = [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
184 ("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
185 ]
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='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
187 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
188 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
189 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
190
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
191 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
192 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
193 [("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
194 ("c", "yyy\t\nyyy"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
195 ("d", "\txyz\n")])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
196 ])
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='' c="">""", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
198 ("starttag", "a", [("b", ""), ("c", "")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
199 ])
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_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
202 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
203 ("starttag", "a", [("b", "&><\"'")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
204 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
205
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
206 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
207 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
208 ("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
209 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
210
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
211 def test_illegal_declarations(self):
19687
3731ad1d9033 HTMLParser is allowed to be more strict than sgmllib, so let's not
Fred Drake <fdrake@acm.org>
parents: 19683
diff changeset
212 self._parse_error('<!spacer type="block" height="25">')
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
213
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
214 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
215 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
216 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
217
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
218 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
219 output = [("starttag", "a", [("b", "<")])]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
220 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
221 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
222 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
223 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
224 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
225 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
226
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
227 output = [("starttag", "a", [("b", ">")])]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
228 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
229 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
230 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
231 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
232 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
233 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
234
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
235 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
236 self._parse_error("</>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
237 self._parse_error("</$>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
238 self._parse_error("</")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
239 self._parse_error("</a")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
240 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
241 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
242 self._parse_error("<!")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
243 self._parse_error("<a $>")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
244 self._parse_error("<a")
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
245 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
246 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
247 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
248 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
249 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
250
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
251 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
252 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
253
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
254 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
255 self._run_check("<p/>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
256 ("startendtag", "p", []),
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 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
259 ("starttag", "p", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
260 ("endtag", "p"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
261 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
262 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
263 ("starttag", "p", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
264 ("startendtag", "img", [("src", "foo")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
265 ("endtag", "p"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
266 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
267
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
268 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
269 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
270 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
271 ("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
272 ("starttag_text", s)])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
273
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
274 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
275 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
276 self._run_check(s, [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
277 ("starttag", "script", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
278 ("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
279 ("endtag", "script"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
280 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
281 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
282 self._run_check(s, [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
283 ("starttag", "script", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
284 ("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
285 ("endtag", "script"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
286 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
287
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
288
20069
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
289 def test_main():
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
290 test_support.run_unittest(HTMLParserTestCase)
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
291
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
292
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
293 if __name__ == "__main__":
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
294 test_main()