##// END OF EJS Templates
check that PIL can save JPEG to BytesIO...
MinRK -
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,27 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 from PIL import Image
66 buf = BytesIO()
67 img = Image.new("RGB", (4,4))
68 try:
69 img.save(buf, 'jpeg')
70 except Exception as e:
71 ename = e.__class__.__name__
72 raise SkipTest("PIL can't write JPEG to BytesIO: %s: %s" % (ename, e))
73
60 74 @dec.skip_without("PIL.Image")
61 def test_figure_to_jpg():
62 # simple check for at least jpg-looking output
75 def test_figure_to_jpeg():
76 _check_pil_jpeg_bytes()
77 # simple check for at least jpeg-looking output
63 78 fig = plt.figure()
64 79 ax = fig.add_subplot(1,1,1)
65 80 ax.plot([1,2,3])
66 81 plt.draw()
67 jpg = pt.print_figure(fig, 'jpg', quality=50)[:100].lower()
68 assert jpg.startswith(_JPEG)
82 jpeg = pt.print_figure(fig, 'jpeg', quality=50)[:100].lower()
83 assert jpeg.startswith(_JPEG)
69 84
70 85 def test_retina_figure():
71 86 fig = plt.figure()
General Comments 0
You need to be logged in to leave comments. Login now