Skip to content

Commit 761f3ab

Browse files
committed
Add a test for HTMLParser(debug=True)
1 parent a137d14 commit 761f3ab

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

html5lib/tests/test_parser2.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import absolute_import, division, unicode_literals
22

3+
from six import PY2, text_type
4+
35
import io
46

57
from . import support # noqa
68

79
from html5lib.constants import namespaces
8-
from html5lib import parse
10+
from html5lib import parse, HTMLParser
911

1012

1113
# tests that aren't autogenerated from text files
@@ -56,3 +58,33 @@ def test_duplicate_attribute():
5658
doc = parse('<p class=a class=b>')
5759
el = doc[1][0]
5860
assert el.get("class") == "a"
61+
62+
63+
def test_debug_log():
64+
parser = HTMLParser(debug=True)
65+
parser.parse("<!doctype html><title>a</title><p>b<script>c</script>d</p>e")
66+
67+
expected = [('dataState', 'InitialPhase', 'InitialPhase', 'processDoctype', {'type': 'Doctype'}),
68+
('dataState', 'BeforeHtmlPhase', 'BeforeHtmlPhase', 'processStartTag', {'name': 'title', 'type': 'StartTag'}),
69+
('dataState', 'BeforeHeadPhase', 'BeforeHeadPhase', 'processStartTag', {'name': 'title', 'type': 'StartTag'}),
70+
('dataState', 'InHeadPhase', 'InHeadPhase', 'processStartTag', {'name': 'title', 'type': 'StartTag'}),
71+
('rcdataState', 'TextPhase', 'TextPhase', 'processCharacters', {'type': 'Characters'}),
72+
('dataState', 'TextPhase', 'TextPhase', 'processEndTag', {'name': 'title', 'type': 'EndTag'}),
73+
('dataState', 'InHeadPhase', 'InHeadPhase', 'processStartTag', {'name': 'p', 'type': 'StartTag'}),
74+
('dataState', 'AfterHeadPhase', 'AfterHeadPhase', 'processStartTag', {'name': 'p', 'type': 'StartTag'}),
75+
('dataState', 'InBodyPhase', 'InBodyPhase', 'processStartTag', {'name': 'p', 'type': 'StartTag'}),
76+
('dataState', 'InBodyPhase', 'InBodyPhase', 'processCharacters', {'type': 'Characters'}),
77+
('dataState', 'InBodyPhase', 'InBodyPhase', 'processStartTag', {'name': 'script', 'type': 'StartTag'}),
78+
('dataState', 'InBodyPhase', 'InHeadPhase', 'processStartTag', {'name': 'script', 'type': 'StartTag'}),
79+
('scriptDataState', 'TextPhase', 'TextPhase', 'processCharacters', {'type': 'Characters'}),
80+
('dataState', 'TextPhase', 'TextPhase', 'processEndTag', {'name': 'script', 'type': 'EndTag'}),
81+
('dataState', 'InBodyPhase', 'InBodyPhase', 'processCharacters', {'type': 'Characters'}),
82+
('dataState', 'InBodyPhase', 'InBodyPhase', 'processEndTag', {'name': 'p', 'type': 'EndTag'}),
83+
('dataState', 'InBodyPhase', 'InBodyPhase', 'processCharacters', {'type': 'Characters'})]
84+
85+
if PY2:
86+
for i, log in enumerate(expected):
87+
log = [x.encode("ascii") if isinstance(x, text_type) else x for x in log]
88+
expected[i] = tuple(log)
89+
90+
assert parser.log == expected

0 commit comments

Comments
 (0)