Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_htmlparser.py @ 64166:d0e9febfa00a 3.1
Merged revisions 84172 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r84172 | martin.v.loewis | 2010-08-18 18:12:23 +0200 (Mi, 18 Aug 2010) | 2 lines
Restore GIL in nis_cat in case of error.
........
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Thu, 19 Aug 2010 09:03:03 +0000 |
| parents | 6144760e8350 |
| children | 3546ce1aa355 1cbfeffea19f |
| 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 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 def __init__(self): |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 self.events = [] |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 self.append = self.events.append |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
14 html.parser.HTMLParser.__init__(self) |
|
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 |
|
19683
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
75 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
|
76 parser = collector() |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
77 for s in source: |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
78 parser.feed(s) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
79 parser.close() |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 "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
|
84 "\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
|
85 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
86 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
|
87 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
|
88 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
89 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
|
90 def parse(source=source): |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
91 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
|
92 parser.feed(source) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
93 parser.close() |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
94 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
|
95 |
|
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 class HTMLParserTestCase(TestCaseBase): |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
98 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
99 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
|
100 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
|
101 ("pi", "processing instruction"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
102 ]) |
|
28660
5f1ef1882b25
Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents:
28297
diff
changeset
|
103 self._run_check("<?processing instruction ?>", [ |
|
5f1ef1882b25
Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents:
28297
diff
changeset
|
104 ("pi", "processing instruction ?"), |
|
5f1ef1882b25
Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents:
28297
diff
changeset
|
105 ]) |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
106 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
107 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
|
108 self._run_check(""" |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
109 <!DOCTYPE html PUBLIC 'foo'> |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
110 <HTML>&entity;  |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
111 <!--comment1a |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
112 -></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
|
113 comment1b--> |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
114 <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
|
115 text |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
116 “ |
|
36914
f1eaae7f962d
Bug #1442874: handle "<!>", the empty SGML comment
Georg Brandl <georg@python.org>
parents:
33432
diff
changeset
|
117 <!--comment2a-- --comment2b--><!> |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
118 </Html> |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
119 """, [ |
|
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 ("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
|
122 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
123 ("starttag", "html", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
124 ("entityref", "entity"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
125 ("charref", "32"), |
|
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 ("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
|
128 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
129 ("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
|
130 ("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
|
131 ("charref", "x201C"), |
|
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
132 ("data", "\n"), |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
133 ("comment", "comment2a-- --comment2b"), |
|
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 ("endtag", "html"), |
|
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 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
138 |
|
61890
6144760e8350
Merged revisions 81504 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
139 def test_malformatted_charref(self): |
|
6144760e8350
Merged revisions 81504 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
140 self._run_check("<p>&#bad;</p>", [ |
|
6144760e8350
Merged revisions 81504 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
141 ("starttag", "p", []), |
|
6144760e8350
Merged revisions 81504 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
142 ("data", "&#bad;"), |
|
6144760e8350
Merged revisions 81504 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
143 ("endtag", "p"), |
|
6144760e8350
Merged revisions 81504 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
144 ]) |
|
6144760e8350
Merged revisions 81504 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
145 |
|
21157
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
146 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
|
147 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
|
148 ("entityref", "entityref"), |
|
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
149 ("data", " foo"), |
|
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
150 ]) |
|
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
151 |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
152 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
|
153 inside = """\ |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
154 DOCTYPE html [ |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
155 <!ELEMENT html - O EMPTY> |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
156 <!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
|
157 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
|
158 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
|
159 <!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
|
160 <!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
|
161 <!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
|
162 <!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
|
163 %paramEntity; |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
164 <!-- comment --> |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
165 ]""" |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
166 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
|
167 ("decl", inside), |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
168 ]) |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
169 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
170 def test_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
|
171 # 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
|
172 # 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
|
173 # 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
|
174 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
|
175 ("starttag", "a", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
176 ("starttag", "b", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
177 ("endtag", "a"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
178 ("endtag", "b"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
179 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
180 |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
181 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
|
182 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
|
183 ("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
|
184 ]) |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
185 |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
186 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
|
187 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
|
188 ("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
|
189 ]) |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
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_syntax(self): |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
192 output = [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
193 ("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
|
194 ] |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
195 self._run_check("""<a b='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
|
196 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
|
197 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
|
198 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
|
199 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
200 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
|
201 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
|
202 [("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
|
203 ("c", "yyy\t\nyyy"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
204 ("d", "\txyz\n")]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
205 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
206 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
|
207 ("starttag", "a", [("b", ""), ("c", "")]), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
208 ]) |
|
28297
2c22b5c09a58
Accept commas in unquoted attribute values.
Fred Drake <fdrake@acm.org>
parents:
24364
diff
changeset
|
209 # Regression test for SF patch #669683. |
|
2c22b5c09a58
Accept commas in unquoted attribute values.
Fred Drake <fdrake@acm.org>
parents:
24364
diff
changeset
|
210 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
|
211 ("starttag", "e", [("a", "rgb(1,2,3)")]), |
|
2c22b5c09a58
Accept commas in unquoted attribute values.
Fred Drake <fdrake@acm.org>
parents:
24364
diff
changeset
|
212 ]) |
|
32538
4fab4a5cce2f
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
32256
diff
changeset
|
213 # 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
|
214 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
|
215 ("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
|
216 ]) |
|
17854
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_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
|
219 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
|
220 ("starttag", "a", [("b", "&><\"'")]), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
221 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
222 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
223 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
|
224 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
|
225 ("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
|
226 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
227 |
|
19683
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
228 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
|
229 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
|
230 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
231 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
|
232 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
|
233 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
|
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_buffer_artefacts(self): |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
236 output = [("starttag", "a", [("b", "<")])] |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
244 output = [("starttag", "a", [("b", ">")])] |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 |
|
33432
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
265 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
|
266 self._parse_error("</>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
267 self._parse_error("</$>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
268 self._parse_error("</") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
269 self._parse_error("</a") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
270 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
|
271 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
|
272 self._parse_error("<!") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
273 self._parse_error("<a $>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
274 self._parse_error("<a") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
281 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
|
282 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
|
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_startendtag(self): |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
285 self._run_check("<p/>", [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
286 ("startendtag", "p", []), |
|
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 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
|
289 ("starttag", "p", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
290 ("endtag", "p"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
291 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
292 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
|
293 ("starttag", "p", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
294 ("startendtag", "img", [("src", "foo")]), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
295 ("endtag", "p"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
296 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
297 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
298 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
|
299 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
|
300 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
|
301 ("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
|
302 ("starttag_text", s)]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
303 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
304 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
|
305 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
|
306 self._run_check(s, [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
307 ("starttag", "script", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
308 ("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
|
309 ("endtag", "script"), |
|
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 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
|
312 self._run_check(s, [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
313 ("starttag", "script", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
314 ("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
|
315 ("endtag", "script"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
316 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
317 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
36914
diff
changeset
|
318 def test_entityrefs_in_attributes(self): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
36914
diff
changeset
|
319 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
|
320 ("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
|
321 ]) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
36914
diff
changeset
|
322 |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
323 |
|
20069
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
324 def test_main(): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
45471
diff
changeset
|
325 support.run_unittest(HTMLParserTestCase) |
|
20069
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
326 |
|
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
327 |
|
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
328 if __name__ == "__main__": |
|
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
329 test_main() |
