|
7 | 7 | from . import support # flake8: noqa
|
8 | 8 | from html5lib import html5parser
|
9 | 9 | from html5lib.constants import namespaces
|
10 |
| -from html5lib import treebuilders |
| 10 | +from html5lib import parse |
11 | 11 |
|
12 | 12 |
|
13 | 13 | # tests that aren't autogenerated from text files
|
14 |
| -@pytest.fixture |
15 |
| -def dom_tree(): |
16 |
| - return treebuilders.getTreeBuilder("dom") |
17 |
| - |
18 |
| - |
19 |
| -def test_assertDoctypeCloneable(dom_tree): |
20 |
| - parser = html5parser.HTMLParser(tree=dom_tree) |
21 |
| - doc = parser.parse('<!DOCTYPE HTML>') |
| 14 | +def test_assertDoctypeCloneable(): |
| 15 | + doc = parse('<!DOCTYPE HTML>', treebuilder="dom") |
22 | 16 | assert doc.cloneNode(True) is not None
|
23 | 17 |
|
24 | 18 |
|
25 |
| -def test_line_counter(dom_tree): |
| 19 | +def test_line_counter(): |
26 | 20 | # http://groups.google.com/group/html5lib-discuss/browse_frm/thread/f4f00e4a2f26d5c0
|
27 |
| - parser = html5parser.HTMLParser(tree=dom_tree) |
28 |
| - parser.parse("<pre>\nx\n>\n</pre>") |
| 21 | + assert parse("<pre>\nx\n>\n</pre>") is not None |
29 | 22 |
|
30 | 23 |
|
31 |
| -def test_namespace_html_elements_0_dom(dom_tree): |
32 |
| - parser = html5parser.HTMLParser(tree=dom_tree, namespaceHTMLElements=True) |
33 |
| - doc = parser.parse("<html></html>") |
| 24 | +def test_namespace_html_elements_0_dom(): |
| 25 | + doc = parse("<html></html>", |
| 26 | + treebuilder="dom", |
| 27 | + namespaceHTMLElements=True) |
34 | 28 | assert doc.childNodes[0].namespaceURI == namespaces["html"]
|
35 | 29 |
|
36 | 30 |
|
37 |
| -def test_namespace_html_elements_1_dom(dom_tree): |
38 |
| - parser = html5parser.HTMLParser(tree=dom_tree, namespaceHTMLElements=False) |
39 |
| - doc = parser.parse("<html></html>") |
| 31 | +def test_namespace_html_elements_1_dom(): |
| 32 | + doc = parse("<html></html>", |
| 33 | + treebuilder="dom", |
| 34 | + namespaceHTMLElements=False) |
40 | 35 | assert doc.childNodes[0].namespaceURI is None
|
41 | 36 |
|
42 | 37 |
|
43 | 38 | def test_namespace_html_elements_0_etree():
|
44 |
| - parser = html5parser.HTMLParser(namespaceHTMLElements=True) |
45 |
| - doc = parser.parse("<html></html>") |
| 39 | + doc = parse("<html></html>", |
| 40 | + treebuilder="etree", |
| 41 | + namespaceHTMLElements=True) |
46 | 42 | assert doc.tag == "{%s}html" % (namespaces["html"],)
|
47 | 43 |
|
48 | 44 |
|
49 | 45 | def test_namespace_html_elements_1_etree():
|
50 |
| - parser = html5parser.HTMLParser(namespaceHTMLElements=False) |
51 |
| - doc = parser.parse("<html></html>") |
| 46 | + doc = parse("<html></html>", |
| 47 | + treebuilder="etree", |
| 48 | + namespaceHTMLElements=False) |
52 | 49 | assert doc.tag == "html"
|
53 | 50 |
|
54 | 51 |
|
55 | 52 | def test_unicode_file():
|
56 |
| - parser = html5parser.HTMLParser() |
57 |
| - parser.parse(io.StringIO("a")) |
| 53 | + assert parse(io.StringIO("a")) is not None |
0 commit comments