Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_htmlparser.py @ 74905:3f9531a4ef09 3.2
Fix htmlparser tests to always use the right collector.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Mon, 13 Feb 2012 14:11:27 +0200 |
| parents | df5e5eea7833 |
| children | 4c4ff9fd19b6 |
line wrap: on
line diff
--- a/Lib/test/test_htmlparser.py Mon Feb 13 11:24:50 2012 +0200 +++ b/Lib/test/test_htmlparser.py Mon Feb 13 14:11:27 2012 +0200 @@ -93,7 +93,7 @@ def _parse_error(self, source): def parse(source=source): - parser = html.parser.HTMLParser() + parser = self.get_collector() parser.feed(source) parser.close() self.assertRaises(html.parser.HTMLParseError, parse) @@ -368,6 +368,30 @@ ('comment', '/img'), ('endtag', 'html<')]) + def test_starttag_junk_chars(self): + self._run_check("</>", []) + self._run_check("</$>", [('comment', '$')]) + self._run_check("</", [('data', '</')]) + self._run_check("</a", [('data', '</a')]) + # XXX this might be wrong + self._run_check("<a<a>", [('data', '<a'), ('starttag', 'a', [])]) + self._run_check("</a<a>", [('endtag', 'a<a')]) + self._run_check("<!", [('data', '<!')]) + self._run_check("<a", [('data', '<a')]) + self._run_check("<a foo='bar'", [('data', "<a foo='bar'")]) + self._run_check("<a foo='bar", [('data', "<a foo='bar")]) + self._run_check("<a foo='>'", [('data', "<a foo='>'")]) + self._run_check("<a foo='>", [('data', "<a foo='>")]) + + def test_declaration_junk_chars(self): + # XXX this is wrong + self._run_check("<!DOCTYPE foo $ >", [('comment', 'DOCTYPE foo $ ')]) + + def test_illegal_declarations(self): + # XXX this might be wrong + self._run_check('<!spacer type="block" height="25">', + [('comment', 'spacer type="block" height="25"')]) + def test_with_unquoted_attributes(self): # see #12008 html = ("<html><body bgcolor=d0ca90 text='181008'>" @@ -476,7 +500,7 @@ self._run_check(html, expected) def test_unescape_function(self): - p = html.parser.HTMLParser() + p = self.get_collector() self.assertEqual(p.unescape('&#bad;'),'&#bad;') self.assertEqual(p.unescape('&'),'&') # see #12888
