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

Skip to content

Commit 573e1dd

Browse files
committed
TST: if no converter is found, skip the test
1 parent 4f14fc8 commit 573e1dd

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

lib/matplotlib/testing/compare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ def convert(filename, cache):
166166
"""
167167
base, extension = filename.rsplit('.', 1)
168168
if extension not in converter:
169-
raise ImageComparisonFailure(
170-
"Don't know how to convert %s files to png" % extension)
169+
from nose import SkipTest
170+
raise SkipTest("Don't know how to convert %s files to png" % extension)
171171
newname = base + '_' + extension + '.png'
172172
if not os.path.exists(filename):
173173
raise IOError("'%s' does not exist" % filename)

visual_tests.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 visual_tests.py
7+
#
8+
9+
import os
10+
import time
11+
import six
12+
13+
from collections import defaultdict
14+
15+
def run():
16+
# Build a website for visual comparison
17+
image_dir = "result_images"
18+
# build the website
19+
_html = ""
20+
_html += """<html><head><style media="screen" type="text/css">
21+
img{
22+
width:100%;
23+
max-width:800px;
24+
}
25+
</style>
26+
</head><body>\n"""
27+
_subdirs = [name for name in os.listdir(image_dir) if os.path.isdir(os.path.join(image_dir, name))]
28+
# loop over all pictures
29+
_row = '<tr><td>{0} {1}</td><td>{2}</td><td><a href="{3}"><img src="{3}"></a></td><td>{4}</td>\n'
30+
_failed = ""
31+
_failed += "<h2>Only Failed</h2>"
32+
_failed += "<table>\n<thead><td>name</td><td>actual</td><td>expected</td><td>diff</td></thead>\n"
33+
_has_failure = False
34+
_body = ""
35+
for subdir in _subdirs:
36+
pictures = defaultdict(dict)
37+
for file in os.listdir(os.path.join(image_dir, subdir)):
38+
if os.path.isdir(os.path.join(image_dir, subdir, file)):
39+
continue
40+
fn, fext = os.path.splitext(file)
41+
if fext != ".png":
42+
continue
43+
if "-failed-diff" in fn:
44+
pictures[fn[:-12]]["f"] = os.path.join(subdir, file)
45+
elif "-expected" in fn:
46+
pictures[fn[:-9]]["e"] = os.path.join(subdir, file)
47+
else:
48+
pictures[fn]["c"] = os.path.join(subdir, file)
49+
50+
_body += "<h2>{0}</h2>".format(subdir)
51+
_body += "<table>\n<thead><td>name</td><td>actual</td><td>expected</td><td>diff</td></thead>\n"
52+
for name, test in six.iteritems(pictures):
53+
if test.get("f", None):
54+
# a real failure in the image generation, resulting in different images
55+
_has_failure = True
56+
s = "(failed)"
57+
failed = '<a href="{0}">diff</a>'.format(test.get("f", ""))
58+
current = '<a href="{0}"><img src="{0}"></a>'.format(test.get("c", ""))
59+
_failed += _row.format(name, "", current, test.get("e", ""), failed)
60+
elif test.get("c", None) is None:
61+
# A failure in the test, resulting in no current image
62+
_has_failure = True
63+
s = "(failed)"
64+
failed = '--'
65+
current = '(Failure in test, no image produced)'
66+
_failed += _row.format(name, "", current, test.get("e", ""), failed)
67+
else:
68+
s = "(passed)"
69+
failed = '--'
70+
current = '<a href="{0}"><img src="{0}"></a>'.format(test.get("c", ""))
71+
_body += _row.format(name, "", current, test.get("e", ""), failed)
72+
_body += "</table>\n"
73+
_failed += "</table>\n"
74+
if _has_failure:
75+
_html += _failed
76+
_html += _body
77+
_html += "\n</body></html>"
78+
index = os.path.join(image_dir, "index.html")
79+
with open(index, "w") as f:
80+
f.write(_html)
81+
try:
82+
import webbrowser
83+
webbrowser.open(index)
84+
except:
85+
print("Open {0} in a browser for a visual comparison.".format(str(index)))
86+
87+
if __name__ == '__main__':
88+
run()

0 commit comments

Comments
 (0)