Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_htmlparser.py @ 71285:8bc9dbc61ba6 3.2
Issue #12326: document the recommended idiom for checking sys.platform on Unix systems.
Also, point to the various alternatives.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sat, 09 Jul 2011 15:54:23 +0200 |
| parents | 225400cb6e84 |
| children | 9896fc2a8167 |
| 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 |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
3 import html.parser |
|
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 unittest |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
45471
diff
changeset
|
6 from test import support |
|
17854
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 |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
9 class EventCollector(html.parser.HTMLParser): |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
11 def __init__(self, *args, **kw): |
|
17854
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 |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
14 html.parser.HTMLParser.__init__(self, *args, **kw) |
|
17854
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 |
|
19683
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
62 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
|
63 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
|
64 |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
65 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
66 class EventCollectorExtra(EventCollector): |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
67 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 |
|
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 class TestCaseBase(unittest.TestCase): |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
74 |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
75 def _run_check(self, source, expected_events, collector=None): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
76 if collector is None: |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
77 collector = EventCollector() |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
78 parser = collector |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
79 for s in source: |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
80 parser.feed(s) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
81 parser.close() |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 "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
|
86 "\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
|
87 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
88 def _run_check_extra(self, source, events): |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
89 self._run_check(source, events, EventCollectorExtra()) |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
90 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
91 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
|
92 def parse(source=source): |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
93 parser = html.parser.HTMLParser() |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
94 parser.feed(source) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
95 parser.close() |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
96 self.assertRaises(html.parser.HTMLParseError, parse) |
|
17854
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 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
99 class HTMLParserTestCase(TestCaseBase): |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
100 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
101 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
|
102 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
|
103 ("pi", "processing instruction"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
104 ]) |
|
28660
5f1ef1882b25
Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents:
28297
diff
changeset
|
105 self._run_check("<?processing instruction ?>", [ |
|
5f1ef1882b25
Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents:
28297
diff
changeset
|
106 ("pi", "processing instruction ?"), |
|
5f1ef1882b25
Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents:
28297
diff
changeset
|
107 ]) |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
108 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
109 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
|
110 self._run_check(""" |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
111 <!DOCTYPE html PUBLIC 'foo'> |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
112 <HTML>&entity;  |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
113 <!--comment1a |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
114 -></foo><bar><<?pi?></foo<bar |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
115 comment1b--> |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
116 <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
|
117 text |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
118 “ |
|
36914
f1eaae7f962d
Bug #1442874: handle "<!>", the empty SGML comment
Georg Brandl <georg@python.org>
parents:
33432
diff
changeset
|
119 <!--comment2a-- --comment2b--><!> |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
120 </Html> |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
121 """, [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
122 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
123 ("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
|
124 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
125 ("starttag", "html", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
126 ("entityref", "entity"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
127 ("charref", "32"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
128 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
129 ("comment", "comment1a\n-></foo><bar><<?pi?></foo<bar\ncomment1b"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
130 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
131 ("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
|
132 ("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
|
133 ("charref", "x201C"), |
|
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
134 ("data", "\n"), |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
135 ("comment", "comment2a-- --comment2b"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
136 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
137 ("endtag", "html"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
138 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
139 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
140 |
|
61889
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
141 def test_malformatted_charref(self): |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
142 self._run_check("<p>&#bad;</p>", [ |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
143 ("starttag", "p", []), |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
144 ("data", "&#bad;"), |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
145 ("endtag", "p"), |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
146 ]) |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
147 |
|
21157
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
148 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
|
149 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
|
150 ("entityref", "entityref"), |
|
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
151 ("data", " foo"), |
|
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
152 ]) |
|
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
153 |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
154 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
|
155 inside = """\ |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
156 DOCTYPE html [ |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
157 <!ELEMENT html - O EMPTY> |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
158 <!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
|
159 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
|
160 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
|
161 <!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
|
162 <!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
|
163 <!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
|
164 <!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
|
165 %paramEntity; |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
166 <!-- comment --> |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
167 ]""" |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
168 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
|
169 ("decl", inside), |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
170 ]) |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
171 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
172 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
|
173 # 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
|
174 # 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
|
175 # 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
|
176 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
|
177 ("starttag", "a", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
178 ("starttag", "b", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
179 ("endtag", "a"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
180 ("endtag", "b"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
181 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
182 |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
183 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
|
184 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
|
185 ("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
|
186 ]) |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
187 |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
188 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
|
189 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
|
190 ("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
|
191 ]) |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
192 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
193 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
|
194 output = [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
195 ("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
|
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='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
|
198 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
|
199 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
|
200 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
|
201 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
202 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
|
203 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
|
204 [("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
|
205 ("c", "yyy\t\nyyy"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
206 ("d", "\txyz\n")]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
207 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
208 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
|
209 ("starttag", "a", [("b", ""), ("c", "")]), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
210 ]) |
|
28297
2c22b5c09a58
Accept commas in unquoted attribute values.
Fred Drake <fdrake@acm.org>
parents:
24364
diff
changeset
|
211 # Regression test for SF patch #669683. |
|
2c22b5c09a58
Accept commas in unquoted attribute values.
Fred Drake <fdrake@acm.org>
parents:
24364
diff
changeset
|
212 self._run_check("<e a=rgb(1,2,3)>", [ |
|
2c22b5c09a58
Accept commas in unquoted attribute values.
Fred Drake <fdrake@acm.org>
parents:
24364
diff
changeset
|
213 ("starttag", "e", [("a", "rgb(1,2,3)")]), |
|
2c22b5c09a58
Accept commas in unquoted attribute values.
Fred Drake <fdrake@acm.org>
parents:
24364
diff
changeset
|
214 ]) |
|
32538
4fab4a5cce2f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
32256
diff
changeset
|
215 # Regression test for SF bug #921657. |
|
32256
2f5f38f4bc2b
[Bug #921657] Allow '@' in unquoted HTML attributes. Not strictly legal according to the HTML REC, but HTMLParser is already a pretty loose parser. Reported by Bernd Zimmermann.
Andrew M. Kuchling <amk@amk.ca>
parents:
28660
diff
changeset
|
216 self._run_check("<a href=mailto:xyz@example.com>", [ |
|
2f5f38f4bc2b
[Bug #921657] Allow '@' in unquoted HTML attributes. Not strictly legal according to the HTML REC, but HTMLParser is already a pretty loose parser. Reported by Bernd Zimmermann.
Andrew M. Kuchling <amk@amk.ca>
parents:
28660
diff
changeset
|
217 ("starttag", "a", [("href", "mailto:xyz@example.com")]), |
|
2f5f38f4bc2b
[Bug #921657] Allow '@' in unquoted HTML attributes. Not strictly legal according to the HTML REC, but HTMLParser is already a pretty loose parser. Reported by Bernd Zimmermann.
Andrew M. Kuchling <amk@amk.ca>
parents:
28660
diff
changeset
|
218 ]) |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
219 |
|
69189
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
220 def test_attr_nonascii(self): |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
221 # see issue 7311 |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
222 self._run_check("<img src=/foo/bar.png alt=\u4e2d\u6587>", [ |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
223 ("starttag", "img", [("src", "/foo/bar.png"), |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
224 ("alt", "\u4e2d\u6587")]), |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
225 ]) |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
226 self._run_check("<a title='\u30c6\u30b9\u30c8' " |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
227 "href='\u30c6\u30b9\u30c8.html'>", [ |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
228 ("starttag", "a", [("title", "\u30c6\u30b9\u30c8"), |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
229 ("href", "\u30c6\u30b9\u30c8.html")]), |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
230 ]) |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
231 self._run_check('<a title="\u30c6\u30b9\u30c8" ' |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
232 'href="\u30c6\u30b9\u30c8.html">', [ |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
233 ("starttag", "a", [("title", "\u30c6\u30b9\u30c8"), |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
234 ("href", "\u30c6\u30b9\u30c8.html")]), |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
235 ]) |
|
225400cb6e84
#7311: fix html.parser to accept non-ASCII attribute values.
Ezio Melotti
parents:
68257
diff
changeset
|
236 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
237 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
|
238 self._run_check("""<a b='&><"''>""", [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
239 ("starttag", "a", [("b", "&><\"'")]), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
240 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
241 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
242 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
|
243 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
|
244 ("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
|
245 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
246 |
|
19683
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
247 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
|
248 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
|
249 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
250 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
|
251 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
|
252 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
|
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_buffer_artefacts(self): |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
255 output = [("starttag", "a", [("b", "<")])] |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
263 output = [("starttag", "a", [("b", ">")])] |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 |
|
33432
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
271 output = [("comment", "abc")] |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
272 self._run_check(["", "<!--abc-->"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
273 self._run_check(["<", "!--abc-->"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
274 self._run_check(["<!", "--abc-->"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
275 self._run_check(["<!-", "-abc-->"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
276 self._run_check(["<!--", "abc-->"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
277 self._run_check(["<!--a", "bc-->"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
278 self._run_check(["<!--ab", "c-->"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
279 self._run_check(["<!--abc", "-->"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
280 self._run_check(["<!--abc-", "->"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
281 self._run_check(["<!--abc--", ">"], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
282 self._run_check(["<!--abc-->", ""], output) |
|
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
283 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
284 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
|
285 self._parse_error("</>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
286 self._parse_error("</$>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
287 self._parse_error("</") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
288 self._parse_error("</a") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
289 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
|
290 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
|
291 self._parse_error("<!") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
292 self._parse_error("<a $>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
293 self._parse_error("<a") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
300 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
|
301 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
|
302 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
303 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
|
304 self._run_check("<p/>", [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
305 ("startendtag", "p", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
306 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
307 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
|
308 ("starttag", "p", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
309 ("endtag", "p"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
310 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
311 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
|
312 ("starttag", "p", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
313 ("startendtag", "img", [("src", "foo")]), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
314 ("endtag", "p"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
315 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
316 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 ("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
|
321 ("starttag_text", s)]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
322 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
323 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
|
324 s = """<script> <!-- not a comment --> ¬-an-entity-ref; </script>""" |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
325 self._run_check(s, [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
326 ("starttag", "script", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
327 ("data", " <!-- not a comment --> ¬-an-entity-ref; "), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
328 ("endtag", "script"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
329 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
330 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
|
331 self._run_check(s, [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
332 ("starttag", "script", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
333 ("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
|
334 ("endtag", "script"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
335 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
336 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
36914
diff
changeset
|
337 def test_entityrefs_in_attributes(self): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
36914
diff
changeset
|
338 self._run_check("<html foo='€&aa&unsupported;'>", [ |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
339 ("starttag", "html", [("foo", "\u20AC&aa&unsupported;")]) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
36914
diff
changeset
|
340 ]) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
36914
diff
changeset
|
341 |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
342 |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
343 class HTMLParserTolerantTestCase(TestCaseBase): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
344 |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
345 def setUp(self): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
346 self.collector = EventCollector(strict=False) |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
347 |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
348 def test_tolerant_parsing(self): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
349 self._run_check('<html <html>te>>xt&a<<bc</a></html>\n' |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
350 '<img src="URL><//img></html</html>', [ |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
351 ('data', '<html '), |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
352 ('starttag', 'html', []), |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
353 ('data', 'te>>xt'), |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
354 ('entityref', 'a'), |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
355 ('data', '<<bc'), |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
356 ('endtag', 'a'), |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
357 ('endtag', 'html'), |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
358 ('data', '\n<img src="URL><//img></html'), |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
359 ('endtag', 'html')], |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
360 collector = self.collector) |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
361 |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
362 def test_comma_between_attributes(self): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
363 self._run_check('<form action="/xxx.php?a=1&b=2&", ' |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
364 'method="post">', [ |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
365 ('starttag', 'form', |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
366 [('action', '/xxx.php?a=1&b=2&'), |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
367 ('method', 'post')])], |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
368 collector = self.collector) |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
369 |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
370 def test_weird_chars_in_unquoted_attribute_values(self): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
371 self._run_check('<form action=bogus|&#()value>', [ |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
372 ('starttag', 'form', |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
373 [('action', 'bogus|&#()value')])], |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
374 collector = self.collector) |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
375 |
|
67189
3546ce1aa355
Merged revisions 87542 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61889
diff
changeset
|
376 def test_unescape_function(self): |
|
3546ce1aa355
Merged revisions 87542 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61889
diff
changeset
|
377 p = html.parser.HTMLParser() |
|
3546ce1aa355
Merged revisions 87542 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61889
diff
changeset
|
378 self.assertEqual(p.unescape('&#bad;'),'&#bad;') |
|
3546ce1aa355
Merged revisions 87542 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61889
diff
changeset
|
379 self.assertEqual(p.unescape('&'),'&') |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
36914
diff
changeset
|
380 |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
381 |
|
20069
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
382 def test_main(): |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
383 support.run_unittest(HTMLParserTestCase, HTMLParserTolerantTestCase) |
|
20069
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
384 |
|
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
385 |
|
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
386 if __name__ == "__main__": |
|
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
387 test_main() |
