##// END OF EJS Templates
check that PIL can save JPEG to BytesIO...
MinRK -
Show More
@@ -13,10 +13,13 b''
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 from __future__ import print_function
14 from __future__ import print_function
15
15
16 from io import UnsupportedOperation, BytesIO
17
16 import matplotlib
18 import matplotlib
17 matplotlib.use('Agg')
19 matplotlib.use('Agg')
18 from matplotlib.figure import Figure
20 from matplotlib.figure import Figure
19
21
22 from nose import SkipTest
20 import nose.tools as nt
23 import nose.tools as nt
21
24
22 from matplotlib import pyplot as plt
25 from matplotlib import pyplot as plt
@@ -57,15 +60,27 b' def test_figure_to_svg():'
57 svg = pt.print_figure(fig, 'svg')[:100].lower()
60 svg = pt.print_figure(fig, 'svg')[:100].lower()
58 nt.assert_in(b'doctype svg', svg)
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 @dec.skip_without("PIL.Image")
74 @dec.skip_without("PIL.Image")
61 def test_figure_to_jpg():
75 def test_figure_to_jpeg():
62 # simple check for at least jpg-looking output
76 _check_pil_jpeg_bytes()
77 # simple check for at least jpeg-looking output
63 fig = plt.figure()
78 fig = plt.figure()
64 ax = fig.add_subplot(1,1,1)
79 ax = fig.add_subplot(1,1,1)
65 ax.plot([1,2,3])
80 ax.plot([1,2,3])
66 plt.draw()
81 plt.draw()
67 jpg = pt.print_figure(fig, 'jpg', quality=50)[:100].lower()
82 jpeg = pt.print_figure(fig, 'jpeg', quality=50)[:100].lower()
68 assert jpg.startswith(_JPEG)
83 assert jpeg.startswith(_JPEG)
69
84
70 def test_retina_figure():
85 def test_retina_figure():
71 fig = plt.figure()
86 fig = plt.figure()
General Comments 0
You need to be logged in to leave comments. Login now