Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix test visualization tool for non-PNG files #27470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion tools/triage_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def __init__(self, path, root, source):
if basename.endswith(f'_{ext}'):
display_extension = f'_{ext}'
extension = ext
basename = basename[:-4]
basename = basename[:-len(display_extension)]
break
else:
display_extension = ''
Expand Down
49 changes: 36 additions & 13 deletions tools/visualize_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
import os
from collections import defaultdict


html_template = """<html><head><style media="screen" type="text/css">
# Non-png image extensions
NON_PNG_EXTENSIONS = ['pdf', 'svg', 'eps']

html_template = """<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<title>Matplotlib test result visualization</title>
<style media="screen">
img{{
width:100%;
max-width:800px;
Expand All @@ -24,14 +30,18 @@
"""

subdir_template = """<h2>{subdir}</h2><table>
<thead><td>name</td><td>actual</td><td>expected</td><td>diff</td></thead>
<thead><tr><th>name</th><th>actual</th><th>expected</th><th>diff</th></tr></thead>
<tbody>
{rows}
</tbody>
</table>
"""

failed_template = """<h2>Only Failed</h2><table>
<thead><td>name</td><td>actual</td><td>expected</td><td>diff</td></thead>
<thead><tr><th>name</th><th>actual</th><th>expected</th><th>diff</th></tr></thead>
<tbody>
{rows}
</tbody>
</table>
"""

Expand Down Expand Up @@ -68,28 +78,41 @@ def run(show_browser=True):
fn, fext = os.path.splitext(file)
if fext != ".png":
continue
# Always use / for URLs.
if "-failed-diff" in fn:
pictures[fn[:-12]]["f"] = "/".join((subdir, file))
file_type = 'diff'
test_name = fn[:-len('-failed-diff')]
elif "-expected" in fn:
pictures[fn[:-9]]["e"] = "/".join((subdir, file))
for ext in NON_PNG_EXTENSIONS:
if fn.endswith(f'_{ext}'):
display_extension = f'_{ext}'
extension = ext
fn = fn[:-len(display_extension)]
break
else:
display_extension = ''
extension = 'png'
file_type = 'expected'
test_name = fn[:-len('-expected')] + display_extension
else:
pictures[fn]["c"] = "/".join((subdir, file))
file_type = 'actual'
test_name = fn
# Always use / for URLs.
pictures[test_name][file_type] = '/'.join((subdir, file))

subdir_rows = []
for name, test in sorted(pictures.items()):
expected_image = test.get('e', '')
actual_image = test.get('c', '')
expected_image = test.get('expected', '')
actual_image = test.get('actual', '')

if 'f' in test:
if 'diff' in test:
# A real failure in the image generation, resulting in
# different images.
status = " (failed)"
failed = f'<a href="{test["f"]}">diff</a>'
failed = f'<a href="{test["diff"]}">diff</a>'
current = linked_image_template.format(actual_image)
failed_rows.append(row_template.format(name, "", current,
expected_image, failed))
elif 'c' not in test:
elif 'actual' not in test:
# A failure in the test, resulting in no current image
status = " (failed)"
failed = '--'
Expand Down