##// END OF EJS Templates
Merge pull request #5277 from minrk/check-jpeg-test...
Thomas Kluyver -
r15690:a5c527b5 merge
parent child Browse files
Show More
@@ -13,10 +13,13 b''
13 13 #-----------------------------------------------------------------------------
14 14 from __future__ import print_function
15 15
16 from io import UnsupportedOperation, BytesIO
17
16 18 import matplotlib
17 19 matplotlib.use('Agg')
18 20 from matplotlib.figure import Figure
19 21
22 from nose import SkipTest
20 23 import nose.tools as nt
21 24
22 25 from matplotlib import pyplot as plt
@@ -57,15 +60,29 b' def test_figure_to_svg():'
57 60 svg = pt.print_figure(fig, 'svg')[:100].lower()
58 61 nt.assert_in(b'doctype svg', svg)
59 62
63 def _check_pil_jpeg_bytes():
64 """Skip if PIL can't write JPEGs to BytesIO objects"""
65 # PIL's JPEG plugin can't write to BytesIO objects
66 # Pillow fixes this
67 from PIL import Image
68 buf = BytesIO()
69 img = Image.new("RGB", (4,4))
70 try:
71 img.save(buf, 'jpeg')
72 except Exception as e:
73 ename = e.__class__.__name__
74 raise SkipTest("PIL can't write JPEG to BytesIO: %s: %s" % (ename, e))
75
60 76 @dec.skip_without("PIL.Image")
61 def test_figure_to_jpg():
62 # simple check for at least jpg-looking output
77 def test_figure_to_jpeg():
78 _check_pil_jpeg_bytes()
79 # simple check for at least jpeg-looking output
63 80 fig = plt.figure()
64 81 ax = fig.add_subplot(1,1,1)
65 82 ax.plot([1,2,3])
66 83 plt.draw()
67 jpg = pt.print_figure(fig, 'jpg', quality=50)[:100].lower()
68 assert jpg.startswith(_JPEG)
84 jpeg = pt.print_figure(fig, 'jpeg', quality=50)[:100].lower()
85 assert jpeg.startswith(_JPEG)
69 86
70 87 def test_retina_figure():
71 88 fig = plt.figure()
General Comments 0
You need to be logged in to leave comments. Login now