Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 87a4c3e

Browse filesBrowse files
authored
Merge pull request #8018 from QuLogic/visual-no-browser
MNT: Cleanup visual_tests and disable browser opening
2 parents 9c14d7e + a4dcd54 commit 87a4c3e
Copy full SHA for 87a4c3e

File tree

Expand file treeCollapse file tree

6 files changed

+152
-103
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+152
-103
lines changed

‎appveyor.yml

Copy file name to clipboardExpand all lines: appveyor.yml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ test_script:
134134
- echo The following args are passed to pytest %PYTEST_ARGS%
135135
- python tests.py %PYTEST_ARGS%
136136
# Generate a html for visual tests
137-
- python visual_tests.py
137+
- python tools/visualize_tests.py --no-browser
138138
- pip install codecov
139139
- codecov -e PYTHON_VERSION PLATFORM
140140

@@ -175,7 +175,7 @@ artifacts:
175175
on_finish:
176176

177177
on_failure:
178-
- python visual_tests.py
178+
- python tools/visualize_tests.py --no-browser
179179
- echo zipping images after a failure...
180180
- 7z a result_images.zip result_images\ |grep -v "Compressing"
181181
- appveyor PushArtifact result_images.zip

‎pytest.ini

Copy file name to clipboardExpand all lines: pytest.ini
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
norecursedirs = .git build ci dist doc extern lib/mpl_examples release tools unit venv
2+
norecursedirs = .git build ci dist doc extern lib/mpl_examples release unit venv
33
python_files = test_*.py
44

55
markers =
@@ -15,7 +15,10 @@ pep8ignore =
1515
setupext.py E301 E302 E501
1616
setup_external_compile.py E302 E501 E711
1717
versioneer.py ALL # External file.
18-
visual_tests.py E302 E501
18+
19+
tools/gh_api.py ALL # External file.
20+
tools/github_stats.py ALL # External file.
21+
tools/subset.py E221 E231 E251 E261 E302 E501 E701 E703
1922

2023
matplotlib/backends/qt_editor/formlayout.py E301 E402 E501
2124
matplotlib/backends/backend_agg.py E225 E228 E231 E261 E301 E302 E303 E501 E701

‎tools/make_icons.py

Copy file name to clipboardExpand all lines: tools/make_icons.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
import matplotlib
14-
matplotlib.use('agg')
14+
matplotlib.use('agg') # noqa
1515

1616
import six
1717

‎tools/test_triage.py renamed to ‎tools/triage_tests.py

Copy file name to clipboardExpand all lines: tools/triage_tests.py
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
If you ran the tests from the top-level of a source checkout, simply run:
1313
14-
python tools/test_triage.py
14+
python tools/triage_tests.py
1515
1616
Otherwise, you can manually select the location of `result_images`
1717
on the commandline.
@@ -187,8 +187,8 @@ def set_entry(self, index):
187187
def set_large_image(self, index):
188188
self.thumbnails[self.current_thumbnail].setFrameShape(0)
189189
self.current_thumbnail = index
190-
pixmap = QtGui.QPixmap(
191-
self.entries[self.current_entry].thumbnails[self.current_thumbnail])
190+
pixmap = QtGui.QPixmap(self.entries[self.current_entry]
191+
.thumbnails[self.current_thumbnail])
192192
self.image_display.setPixmap(pixmap)
193193
self.thumbnails[self.current_thumbnail].setFrameShape(1)
194194

@@ -212,9 +212,9 @@ def keyPressEvent(self, e):
212212
elif e.key() == QtCore.Qt.Key_Right:
213213
self.set_large_image((self.current_thumbnail + 1) % 3)
214214
elif e.key() == QtCore.Qt.Key_Up:
215-
self.set_entry(max((self.current_entry - 1), 0))
215+
self.set_entry(max(self.current_entry - 1, 0))
216216
elif e.key() == QtCore.Qt.Key_Down:
217-
self.set_entry(min((self.current_entry + 1), len(self.entries) - 1))
217+
self.set_entry(min(self.current_entry + 1, len(self.entries) - 1))
218218
elif e.key() == QtCore.Qt.Key_A:
219219
self.accept_test()
220220
elif e.key() == QtCore.Qt.Key_R:
@@ -249,7 +249,8 @@ def __init__(self, path, root, source):
249249
self.extension = extension
250250
self.generated = basename + '.' + extension
251251
self.expected = basename + '-expected.' + extension
252-
self.expected_display = basename + '-expected' + display_extension + '.png'
252+
self.expected_display = (basename + '-expected' + display_extension +
253+
'.png')
253254
self.generated_display = basename + display_extension + '.png'
254255
self.name = os.path.join(self.reldir, self.basename)
255256
self.destdir = self.get_dest_dir(self.reldir)

‎tools/visualize_tests.py

Copy file name to clipboard
+137Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env python
2+
#
3+
# This builds a html page of all images from the image comparison tests
4+
# and opens that page in the browser.
5+
#
6+
# $ python tools/visualize_tests.py
7+
#
8+
9+
import argparse
10+
import os
11+
from collections import defaultdict
12+
13+
14+
html_template = """<html><head><style media="screen" type="text/css">
15+
img{{
16+
width:100%;
17+
max-width:800px;
18+
}}
19+
</style>
20+
</head><body>
21+
{failed}
22+
{body}
23+
</body></html>
24+
"""
25+
26+
subdir_template = """<h2>{subdir}</h2><table>
27+
<thead><td>name</td><td>actual</td><td>expected</td><td>diff</td></thead>
28+
{rows}
29+
</table>
30+
"""
31+
32+
failed_template = """<h2>Only Failed</h2><table>
33+
<thead><td>name</td><td>actual</td><td>expected</td><td>diff</td></thead>
34+
{rows}
35+
</table>
36+
"""
37+
38+
row_template = ('<tr>'
39+
'<td>{0}{1}</td>'
40+
'<td>{2}</td>'
41+
'<td><a href="{3}"><img src="{3}"></a></td>'
42+
'<td>{4}</td>'
43+
'</tr>')
44+
45+
linked_image_template = '<a href="{0}"><img src="{0}"></a>'
46+
47+
48+
def run(show_browser=True):
49+
"""
50+
Build a website for visual comparison
51+
"""
52+
image_dir = "result_images"
53+
_subdirs = (name
54+
for name in os.listdir(image_dir)
55+
if os.path.isdir(os.path.join(image_dir, name)))
56+
57+
failed_rows = []
58+
body_sections = []
59+
for subdir in sorted(_subdirs):
60+
if subdir == "test_compare_images":
61+
# These are the images which test the image comparison functions.
62+
continue
63+
64+
pictures = defaultdict(dict)
65+
for file in os.listdir(os.path.join(image_dir, subdir)):
66+
if os.path.isdir(os.path.join(image_dir, subdir, file)):
67+
continue
68+
fn, fext = os.path.splitext(file)
69+
if fext != ".png":
70+
continue
71+
# Always use / for URLs.
72+
if "-failed-diff" in fn:
73+
pictures[fn[:-12]]["f"] = "/".join((subdir, file))
74+
elif "-expected" in fn:
75+
pictures[fn[:-9]]["e"] = "/".join((subdir, file))
76+
else:
77+
pictures[fn]["c"] = "/".join((subdir, file))
78+
79+
subdir_rows = []
80+
for name, test in sorted(pictures.items()):
81+
expected_image = test.get('e', '')
82+
actual_image = test.get('c', '')
83+
84+
if 'f' in test:
85+
# A real failure in the image generation, resulting in
86+
# different images.
87+
status = " (failed)"
88+
failed = '<a href="{0}">diff</a>'.format(test['f'])
89+
current = linked_image_template.format(actual_image)
90+
failed_rows.append(row_template.format(name, "", current,
91+
expected_image, failed))
92+
elif 'c' not in test:
93+
# A failure in the test, resulting in no current image
94+
status = " (failed)"
95+
failed = '--'
96+
current = '(Failure in test, no image produced)'
97+
failed_rows.append(row_template.format(name, "", current,
98+
expected_image, failed))
99+
else:
100+
status = " (passed)"
101+
failed = '--'
102+
current = linked_image_template.format(actual_image)
103+
104+
subdir_rows.append(row_template.format(name, status, current,
105+
expected_image, failed))
106+
107+
body_sections.append(
108+
subdir_template.format(subdir=subdir, rows='\n'.join(subdir_rows)))
109+
110+
if failed_rows:
111+
failed = failed_template.format(rows='\n'.join(failed_rows))
112+
else:
113+
failed = ''
114+
body = ''.join(body_sections)
115+
html = html_template.format(failed=failed, body=body)
116+
index = os.path.join(image_dir, "index.html")
117+
with open(index, "w") as f:
118+
f.write(html)
119+
120+
show_message = not show_browser
121+
if show_browser:
122+
try:
123+
import webbrowser
124+
webbrowser.open(index)
125+
except:
126+
show_message = True
127+
128+
if show_message:
129+
print("Open {} in a browser for a visual comparison.".format(index))
130+
131+
132+
if __name__ == '__main__':
133+
parser = argparse.ArgumentParser()
134+
parser.add_argument('--no-browser', action='store_true',
135+
help="Don't show browser after creating index page.")
136+
args = parser.parse_args()
137+
run(show_browser=not args.no_browser)

‎visual_tests.py

Copy file name to clipboardExpand all lines: visual_tests.py
-92Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.