Skip to content

Cleanup visual_tests and disable browser opening #8018

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 8 commits into from
Mar 12, 2017
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
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ test_script:
- if x%USE_PYTEST% == xyes py.test %PYTEST_ARGS%
- if x%USE_PYTEST% == xno python tests.py %PYTEST_ARGS%
# Generate a html for visual tests
- python visual_tests.py
- python tools/visualize_tests.py --no-browser
- pip install codecov
- codecov -e PYTHON_VERSION PLATFORM

Expand Down Expand Up @@ -180,7 +180,7 @@ artifacts:
on_finish:

on_failure:
- python visual_tests.py
- python tools/visualize_tests.py --no-browser
- echo zipping images after a failure...
- 7z a result_images.zip result_images\ |grep -v "Compressing"
- appveyor PushArtifact result_images.zip
Expand Down
7 changes: 5 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
norecursedirs = .git build ci dist doc extern lib/mpl_examples release tools unit venv
norecursedirs = .git build ci dist doc extern lib/mpl_examples release unit venv
python_files = test_*.py

markers =
Expand All @@ -15,7 +15,10 @@ pep8ignore =
setupext.py E301 E302 E501
setup_external_compile.py E302 E501 E711
versioneer.py ALL # External file.
visual_tests.py E302 E501

tools/gh_api.py ALL # External file.
tools/github_stats.py ALL # External file.
tools/subset.py E221 E231 E251 E261 E302 E501 E701 E703

matplotlib/backends/qt_editor/formlayout.py E301 E402 E501
matplotlib/backends/backend_agg.py E225 E228 E231 E261 E301 E302 E303 E501 E701
Expand Down
2 changes: 1 addition & 1 deletion tools/make_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

import matplotlib
matplotlib.use('agg')
matplotlib.use('agg') # noqa
Copy link
Member

Choose a reason for hiding this comment

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

What does the comment mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

Skip flake8/pep8 issues with this line. (This line causes a warning about imports not at the top of the file.)


import six

Expand Down
13 changes: 7 additions & 6 deletions tools/test_triage.py → tools/triage_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

If you ran the tests from the top-level of a source checkout, simply run:

python tools/test_triage.py
python tools/triage_tests.py

Otherwise, you can manually select the location of `result_images`
on the commandline.
Expand Down Expand Up @@ -187,8 +187,8 @@ def set_entry(self, index):
def set_large_image(self, index):
self.thumbnails[self.current_thumbnail].setFrameShape(0)
self.current_thumbnail = index
pixmap = QtGui.QPixmap(
self.entries[self.current_entry].thumbnails[self.current_thumbnail])
pixmap = QtGui.QPixmap(self.entries[self.current_entry]
.thumbnails[self.current_thumbnail])
self.image_display.setPixmap(pixmap)
self.thumbnails[self.current_thumbnail].setFrameShape(1)

Expand All @@ -212,9 +212,9 @@ def keyPressEvent(self, e):
elif e.key() == QtCore.Qt.Key_Right:
self.set_large_image((self.current_thumbnail + 1) % 3)
elif e.key() == QtCore.Qt.Key_Up:
self.set_entry(max((self.current_entry - 1), 0))
self.set_entry(max(self.current_entry - 1, 0))
elif e.key() == QtCore.Qt.Key_Down:
self.set_entry(min((self.current_entry + 1), len(self.entries) - 1))
self.set_entry(min(self.current_entry + 1, len(self.entries) - 1))
elif e.key() == QtCore.Qt.Key_A:
self.accept_test()
elif e.key() == QtCore.Qt.Key_R:
Expand Down Expand Up @@ -249,7 +249,8 @@ def __init__(self, path, root, source):
self.extension = extension
self.generated = basename + '.' + extension
self.expected = basename + '-expected.' + extension
self.expected_display = basename + '-expected' + display_extension + '.png'
self.expected_display = (basename + '-expected' + display_extension +
'.png')
self.generated_display = basename + display_extension + '.png'
self.name = os.path.join(self.reldir, self.basename)
self.destdir = self.get_dest_dir(self.reldir)
Expand Down
137 changes: 137 additions & 0 deletions tools/visualize_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/env python
#
# This builds a html page of all images from the image comparison tests
# and opens that page in the browser.
#
# $ python tools/visualize_tests.py
#

import argparse
import os
from collections import defaultdict


html_template = """<html><head><style media="screen" type="text/css">
img{{
width:100%;
max-width:800px;
}}
</style>
</head><body>
{failed}
{body}
</body></html>
"""

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

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

row_template = ('<tr>'
'<td>{0}{1}</td>'
'<td>{2}</td>'
'<td><a href="{3}"><img src="{3}"></a></td>'
'<td>{4}</td>'
'</tr>')

linked_image_template = '<a href="{0}"><img src="{0}"></a>'


def run(show_browser=True):
"""
Build a website for visual comparison
"""
image_dir = "result_images"
_subdirs = (name
for name in os.listdir(image_dir)
if os.path.isdir(os.path.join(image_dir, name)))

failed_rows = []
body_sections = []
for subdir in sorted(_subdirs):
if subdir == "test_compare_images":
# These are the images which test the image comparison functions.
continue

pictures = defaultdict(dict)
for file in os.listdir(os.path.join(image_dir, subdir)):
if os.path.isdir(os.path.join(image_dir, subdir, file)):
continue
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))
elif "-expected" in fn:
pictures[fn[:-9]]["e"] = "/".join((subdir, file))
else:
pictures[fn]["c"] = "/".join((subdir, file))

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

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

subdir_rows.append(row_template.format(name, status, current,
expected_image, failed))

body_sections.append(
subdir_template.format(subdir=subdir, rows='\n'.join(subdir_rows)))

if failed_rows:
failed = failed_template.format(rows='\n'.join(failed_rows))
else:
failed = ''
body = ''.join(body_sections)
html = html_template.format(failed=failed, body=body)
index = os.path.join(image_dir, "index.html")
with open(index, "w") as f:
f.write(html)

show_message = not show_browser
if show_browser:
try:
import webbrowser
webbrowser.open(index)
except:
show_message = True

if show_message:
print("Open {} in a browser for a visual comparison.".format(index))


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--no-browser', action='store_true',
help="Don't show browser after creating index page.")
args = parser.parse_args()
run(show_browser=not args.no_browser)
92 changes: 0 additions & 92 deletions visual_tests.py

This file was deleted.