diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py
index c4a8f17c407..b587ab80d54 100644
--- a/Lib/test/test_htmlparser.py
+++ b/Lib/test/test_htmlparser.py
@@ -72,9 +72,12 @@ def handle_starttag(self, tag, attrs):
class TestCaseBase(unittest.TestCase):
+ def get_collector(self):
+ raise NotImplementedError
+
def _run_check(self, source, expected_events, collector=None):
if collector is None:
- collector = EventCollector()
+ collector = self.get_collector()
parser = collector
for s in source:
parser.feed(s)
@@ -96,7 +99,10 @@ def parse(source=source):
self.assertRaises(html.parser.HTMLParseError, parse)
-class HTMLParserTestCase(TestCaseBase):
+class HTMLParserStrictTestCase(TestCaseBase):
+
+ def get_collector(self):
+ return EventCollector(strict=True)
def test_processing_instruction_only(self):
self._run_check("", [
@@ -353,12 +359,11 @@ def test_cdata_content(self):
def test_entityrefs_in_attributes(self):
- self._run_check("", [
- ("starttag", "html", [("foo", "\u20AC&aa&unsupported;")])
- ])
+ self._run_check("",
+ [("starttag", "html", [("foo", "\u20AC&aa&unsupported;")])])
-class HTMLParserTolerantTestCase(TestCaseBase):
+class HTMLParserTolerantTestCase(HTMLParserStrictTestCase):
def get_collector(self):
return EventCollector(strict=False)
@@ -374,8 +379,7 @@ def test_tolerant_parsing(self):
('endtag', 'a'),
('endtag', 'html'),
('data', '\n', [
('starttag', 'form',
[('action', '/xxx.php?a=1&b=2&'),
- ('method', 'post')])],
- collector=self.get_collector())
+ ('method', 'post')])])
def test_weird_chars_in_unquoted_attribute_values(self):
self._run_check('