Enhanced the test for DOCTYPE declarations, added a test for dealing with
broken declaration-like things.
This commit is contained in:
parent
68eac2b574
commit
c20a698932
@ -60,6 +60,9 @@ class EventCollector(HTMLParser.HTMLParser):
|
|||||||
def handle_pi(self, data):
|
def handle_pi(self, data):
|
||||||
self.append(("pi", data))
|
self.append(("pi", data))
|
||||||
|
|
||||||
|
def unknown_decl(self, decl):
|
||||||
|
self.append(("unknown decl", decl))
|
||||||
|
|
||||||
|
|
||||||
class EventCollectorExtra(EventCollector):
|
class EventCollectorExtra(EventCollector):
|
||||||
|
|
||||||
@ -70,24 +73,16 @@ class EventCollectorExtra(EventCollector):
|
|||||||
|
|
||||||
class TestCaseBase(unittest.TestCase):
|
class TestCaseBase(unittest.TestCase):
|
||||||
|
|
||||||
# Constant pieces of source and events
|
def _run_check(self, source, expected_events, collector=EventCollector):
|
||||||
prologue = ""
|
|
||||||
epilogue = ""
|
|
||||||
initial_events = []
|
|
||||||
final_events = []
|
|
||||||
|
|
||||||
def _run_check(self, source, events, collector=EventCollector):
|
|
||||||
parser = collector()
|
parser = collector()
|
||||||
parser.feed(self.prologue)
|
|
||||||
for s in source:
|
for s in source:
|
||||||
parser.feed(s)
|
parser.feed(s)
|
||||||
for c in self.epilogue:
|
|
||||||
parser.feed(c)
|
|
||||||
parser.close()
|
parser.close()
|
||||||
events = parser.get_events()
|
events = parser.get_events()
|
||||||
self.assertEqual(events,
|
if events != expected_events:
|
||||||
self.initial_events + events + self.final_events,
|
self.fail("received events did not match expected events\n"
|
||||||
"got events:\n" + pprint.pformat(events))
|
"Expected:\n" + pprint.pformat(expected_events) +
|
||||||
|
"\nReceived:\n" + pprint.pformat(events))
|
||||||
|
|
||||||
def _run_check_extra(self, source, events):
|
def _run_check_extra(self, source, events):
|
||||||
self._run_check(source, events, EventCollectorExtra)
|
self._run_check(source, events, EventCollectorExtra)
|
||||||
@ -144,7 +139,13 @@ text
|
|||||||
DOCTYPE html [
|
DOCTYPE html [
|
||||||
<!ELEMENT html - O EMPTY>
|
<!ELEMENT html - O EMPTY>
|
||||||
<!ATTLIST html
|
<!ATTLIST html
|
||||||
version CDATA #IMPLIED '4.0'>
|
version CDATA #IMPLIED
|
||||||
|
profile CDATA 'DublinCore'>
|
||||||
|
<!NOTATION datatype SYSTEM 'http://xml.python.org/notations/python-module'>
|
||||||
|
<!ENTITY myEntity 'internal parsed entity'>
|
||||||
|
<!ENTITY anEntity SYSTEM 'http://xml.python.org/entities/something.xml'>
|
||||||
|
<!ENTITY % paramEntity 'name|name|name'>
|
||||||
|
%paramEntity;
|
||||||
<!-- comment -->
|
<!-- comment -->
|
||||||
]"""
|
]"""
|
||||||
self._run_check("<!%s>" % inside, [
|
self._run_check("<!%s>" % inside, [
|
||||||
@ -201,6 +202,14 @@ DOCTYPE html [
|
|||||||
("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")]),
|
("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")]),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_illegal_declarations(self):
|
||||||
|
s = 'abc<!spacer type="block" height="25">def'
|
||||||
|
self._run_check(s, [
|
||||||
|
("data", "abc"),
|
||||||
|
("unknown decl", 'spacer type="block" height="25"'),
|
||||||
|
("data", "def"),
|
||||||
|
])
|
||||||
|
|
||||||
def test_starttag_end_boundary(self):
|
def test_starttag_end_boundary(self):
|
||||||
self._run_check("""<a b='<'>""", [("starttag", "a", [("b", "<")])])
|
self._run_check("""<a b='<'>""", [("starttag", "a", [("b", "<")])])
|
||||||
self._run_check("""<a b='>'>""", [("starttag", "a", [("b", ">")])])
|
self._run_check("""<a b='>'>""", [("starttag", "a", [("b", ">")])])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user