Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/etc/htmldocck.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def get_tree_count(tree, path):
return len(tree.findall(path))


def check_snapshot(snapshot_name, tree):
def check_snapshot(snapshot_name, tree, normalize_to_text):
assert rust_test_path.endswith('.rs')
snapshot_path = '{}.{}.{}'.format(rust_test_path[:-3], snapshot_name, 'html')
try:
Expand All @@ -413,7 +413,10 @@ def check_snapshot(snapshot_name, tree):
else:
raise FailedCheck('No saved snapshot value')

actual_str = ET.tostring(tree).decode('utf-8')
if not normalize_to_text:
actual_str = ET.tostring(tree).decode('utf-8')
else:
actual_str = flatten(tree)

if expected_str != actual_str:
if bless:
Expand Down Expand Up @@ -494,11 +497,16 @@ def check_command(c, cache):
[snapshot_name, html_path, pattern] = c.args
tree = cache.get_tree(html_path)
xpath = normalize_xpath(pattern)
normalize_to_text = False
if xpath.endswith('/text()'):
xpath = xpath[:-7]
normalize_to_text = True
Comment on lines +501 to +503
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates code elsewhere in htmldocck.


subtrees = tree.findall(xpath)
if len(subtrees) == 1:
[subtree] = subtrees
try:
check_snapshot(snapshot_name, subtree)
check_snapshot(snapshot_name, subtree, normalize_to_text)
ret = True
except FailedCheck as err:
cerr = str(err)
Expand Down