MCPcopy Create free account
hub / github.com/awolverp/markupever / test_parser

Function test_parser

python/tests/test_parser.py:5–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4
5def test_parser(): # this is a copy of test_rustlib.test_parser for markupever.parser.Parser
6 parser = markupever.Parser(markupever.HtmlOptions())
7 parser.process(b"<html><p>Ali</p></html>")
8 parser.finish()
9
10 repr(parser)
11
12 parser = markupever.Parser(markupever.HtmlOptions())
13 parser.process("<html><p>Ali</p></html>")
14
15 with pytest.raises(TypeError):
16 parser.process(1)
17
18 with pytest.raises(RuntimeError):
19 parser.into_dom()
20
21 parser.finish()
22
23 with pytest.raises(RuntimeError):
24 parser.process("")
25
26 with pytest.raises(RuntimeError):
27 parser.finish()
28
29 parser.into_dom()
30 with pytest.raises(RuntimeError):
31 parser.into_dom()
32
33 parser = markupever.Parser(markupever.XmlOptions())
34 for c in ("<html>", b"Ali", b"</html>"):
35 parser.process(c)
36 parser.finish()
37
38 assert parser.is_finished
39 assert isinstance(parser.errors(), list)
40 assert parser.lineno == 1
41 assert parser.quirks_mode == 2
42
43 parser = markupever.Parser(markupever.HtmlOptions(full_document=False))
44 for c in (b"<html><p>Ali</p>", "\n", "</html>"):
45 parser.process(c)
46 parser.finish()
47
48 assert parser.lineno == 2
49
50 _ = parser.into_dom()
51
52 assert parser.is_converted
53
54 with pytest.raises(RuntimeError):
55 parser.errors()
56
57 _ = markupever.Parser("html")
58 _ = markupever.Parser("xml")
59
60 with pytest.raises(ValueError):
61 _ = markupever.Parser("invalid")
62

Callers

nothing calls this directly

Calls 4

processMethod · 0.95
finishMethod · 0.95
into_domMethod · 0.95
errorsMethod · 0.95

Tested by

no test coverage detected