|
1 | 1 | from __future__ import absolute_import, division, unicode_literals
|
2 | 2 |
|
| 3 | +from six import PY2, text_type |
| 4 | + |
3 | 5 | import io
|
4 | 6 |
|
5 | 7 | from . import support # noqa
|
6 | 8 |
|
7 | 9 | from html5lib.constants import namespaces
|
8 |
| -from html5lib import parse |
| 10 | +from html5lib import parse, HTMLParser |
9 | 11 |
|
10 | 12 |
|
11 | 13 | # tests that aren't autogenerated from text files
|
@@ -56,3 +58,33 @@ def test_duplicate_attribute():
|
56 | 58 | doc = parse('<p class=a class=b>')
|
57 | 59 | el = doc[1][0]
|
58 | 60 | 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