mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor test: check_xpath()
This commit is contained in:
parent
871e0b58a8
commit
0dc456fee1
@ -96,15 +96,12 @@ def check_xpath(etree, fname, path, check, be_found=True):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
def get_text(node):
|
def get_text(node):
|
||||||
""" Get all text inside an HTML tag:
|
if node.text is not None:
|
||||||
<foo>My <span>1</span>dog <span>1</span>likes bones</foo> --> My dog likes bones
|
# the node has only one text
|
||||||
"""
|
return node.text
|
||||||
return ''.join(
|
else:
|
||||||
filter(
|
# the node has tags and text; gather texts just under the node
|
||||||
lambda x: x and not re.match(r'^\s+$', x),
|
return ''.join(n.tail or '' for n in node)
|
||||||
[node.text] + [n.tail for n in node.getchildren()]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
rex = re.compile(check)
|
rex = re.compile(check)
|
||||||
if be_found:
|
if be_found:
|
||||||
@ -116,7 +113,7 @@ def check_xpath(etree, fname, path, check, be_found=True):
|
|||||||
|
|
||||||
assert False, ('%r not found in any node matching '
|
assert False, ('%r not found in any node matching '
|
||||||
'path %s in %s: %r' % (check, path, fname,
|
'path %s in %s: %r' % (check, path, fname,
|
||||||
[get_all_text(node) for node in nodes]))
|
[node.text for node in nodes]))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='warnings')
|
@pytest.mark.sphinx('html', testroot='warnings')
|
||||||
|
Loading…
Reference in New Issue
Block a user