|
1 | 1 | """Test HTML output the same way that Sphinx does in test_build_html.py.""" |
2 | 2 |
|
3 | | -import re |
4 | 3 | from itertools import chain, cycle |
5 | 4 | from pathlib import Path |
6 | 5 |
|
7 | 6 | import pytest |
8 | 7 | from docutils import nodes |
9 | 8 | from lxml import etree as lxmltree |
10 | | -from sphinx.testing.path import path as sphinx_path |
11 | 9 | from sphinx.testing.util import SphinxTestApp |
12 | 10 |
|
13 | 11 | pytest_plugins = 'sphinx.testing.fixtures' |
|
17 | 15 |
|
18 | 16 | @pytest.fixture(scope='session') |
19 | 17 | def rootdir(): |
20 | | - return sphinx_path(__file__).parent.abspath() / 'roots' |
| 18 | + return Path(__file__).parent.absolute() / 'roots' |
21 | 19 |
|
22 | 20 |
|
23 | 21 | class SphinxBuilder: |
@@ -73,39 +71,3 @@ def parse(fname): |
73 | 71 |
|
74 | 72 | def flat_dict(d): |
75 | 73 | return chain.from_iterable([zip(cycle([fname]), values) for fname, values in d.items()]) |
76 | | - |
77 | | - |
78 | | -def check_xpath(etree, fname, path, check, be_found=True): |
79 | | - nodes = list(etree.xpath(path)) |
80 | | - if check is None: |
81 | | - assert nodes == [], f'found any nodes matching xpath {path!r} in file {fname}' |
82 | | - return |
83 | | - else: |
84 | | - assert nodes != [], f'did not find any node matching xpath {path!r} in file {fname}' |
85 | | - if callable(check): |
86 | | - check(nodes) |
87 | | - elif not check: |
88 | | - # only check for node presence |
89 | | - pass |
90 | | - else: |
91 | | - |
92 | | - def get_text(node): |
93 | | - if node.text is not None: |
94 | | - # the node has only one text |
95 | | - return node.text |
96 | | - else: |
97 | | - # the node has tags and text; gather texts just under the node |
98 | | - return ''.join(n.tail or '' for n in node) |
99 | | - |
100 | | - rex = re.compile(check) |
101 | | - if be_found: |
102 | | - if any(rex.search(get_text(node)) for node in nodes): |
103 | | - return |
104 | | - else: |
105 | | - if all(not rex.search(get_text(node)) for node in nodes): |
106 | | - return |
107 | | - |
108 | | - raise AssertionError( |
109 | | - f'{check!r} not found in any node matching path {path} in {fname}: ' |
110 | | - f'{[node.text for node in nodes]!r}' |
111 | | - ) |
0 commit comments