Improve `check_xpath`

This commit is contained in:
Adam Turner
2024-01-18 01:21:09 +00:00
parent 898e50c2c7
commit 311ca30564

View File

@@ -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)