mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Improve `check_xpath`
This commit is contained in:
@@ -38,11 +38,11 @@ def check_xpath(etree, fname, path, check, be_found=True):
|
||||
nodes = list(etree.findall(path))
|
||||
if check is None:
|
||||
assert nodes == [], ('found any nodes matching xpath '
|
||||
'%r in file %s' % (path, fname))
|
||||
f'{path!r} in file {fname}')
|
||||
return
|
||||
else:
|
||||
assert nodes != [], ('did not find any node matching xpath '
|
||||
'%r in file %s' % (path, fname))
|
||||
f'{path!r} in file {fname}')
|
||||
if callable(check):
|
||||
check(nodes)
|
||||
elif not check:
|
||||
@@ -65,9 +65,9 @@ def check_xpath(etree, fname, path, check, be_found=True):
|
||||
if all(not rex.search(get_text(node)) for node in nodes):
|
||||
return
|
||||
|
||||
raise AssertionError('%r not found in any node matching '
|
||||
'path %s in %s: %r' % (check, path, fname,
|
||||
[node.text for node in nodes]))
|
||||
msg = (f'{check!r} not found in any node matching '
|
||||
f'{path!r} in file {fname}: {[node.text for node in nodes]!r}')
|
||||
raise AssertionError(msg)
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='warnings', freshenv=True)
|
||||
|
||||
Reference in New Issue
Block a user