Skip to content

Commit ea414f7

Browse files
committed
Use absolute imports
1 parent 993cbda commit ea414f7

File tree

3 files changed

+39
-42
lines changed

3 files changed

+39
-42
lines changed

sphinxarg/ext.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
from docutils.utils import new_document
1515
from sphinx.util.nodes import nested_parse_with_titles
1616

17+
from sphinxarg import __version__
1718
from sphinxarg.parser import parse_parser, parser_navigate
1819

19-
from . import __version__
20-
2120

2221
def map_nested_definitions(nested_content):
2322
if nested_content is None:

test/conftest.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"""Test HTML output the same way that Sphinx does in test_build_html.py."""
22

3-
import re
43
from itertools import chain, cycle
54
from pathlib import Path
65

76
import pytest
87
from docutils import nodes
98
from lxml import etree as lxmltree
10-
from sphinx.testing.path import path as sphinx_path
119
from sphinx.testing.util import SphinxTestApp
1210

1311
pytest_plugins = 'sphinx.testing.fixtures'
@@ -17,7 +15,7 @@
1715

1816
@pytest.fixture(scope='session')
1917
def rootdir():
20-
return sphinx_path(__file__).parent.abspath() / 'roots'
18+
return Path(__file__).parent.absolute() / 'roots'
2119

2220

2321
class SphinxBuilder:
@@ -73,39 +71,3 @@ def parse(fname):
7371

7472
def flat_dict(d):
7573
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-
)

test/test_default_html.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
11
"""Test the HTML builder and check output against XPath."""
22

3+
import re
4+
35
import pytest
46

5-
from .conftest import check_xpath
7+
8+
def check_xpath(etree, fname, path, check, be_found=True):
9+
nodes = list(etree.xpath(path))
10+
if check is None:
11+
assert nodes == [], f'found any nodes matching xpath {path!r} in file {fname}'
12+
return
13+
else:
14+
assert nodes != [], f'did not find any node matching xpath {path!r} in file {fname}'
15+
if callable(check):
16+
check(nodes)
17+
elif not check:
18+
# only check for node presence
19+
pass
20+
else:
21+
22+
def get_text(node):
23+
if node.text is not None:
24+
# the node has only one text
25+
return node.text
26+
else:
27+
# the node has tags and text; gather texts just under the node
28+
return ''.join(n.tail or '' for n in node)
29+
30+
rex = re.compile(check)
31+
if be_found:
32+
if any(rex.search(get_text(node)) for node in nodes):
33+
return
34+
else:
35+
if all(not rex.search(get_text(node)) for node in nodes):
36+
return
37+
38+
raise AssertionError(
39+
f'{check!r} not found in any node matching path {path} in {fname}: '
40+
f'{[node.text for node in nodes]!r}'
41+
)
642

743

844
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)