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,29 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 | # 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 | @dec.skip_without("PIL.Image") |
|
76 | @dec.skip_without("PIL.Image") | |
61 | def test_figure_to_jpg(): |
|
77 | def test_figure_to_jpeg(): | |
62 | # simple check for at least jpg-looking output |
|
78 | _check_pil_jpeg_bytes() | |
|
79 | # simple check for at least jpeg-looking output | |||
63 | fig = plt.figure() |
|
80 | fig = plt.figure() | |
64 | ax = fig.add_subplot(1,1,1) |
|
81 | ax = fig.add_subplot(1,1,1) | |
65 | ax.plot([1,2,3]) |
|
82 | ax.plot([1,2,3]) | |
66 | plt.draw() |
|
83 | plt.draw() | |
67 | jpg = pt.print_figure(fig, 'jpg', quality=50)[:100].lower() |
|
84 | jpeg = pt.print_figure(fig, 'jpeg', quality=50)[:100].lower() | |
68 | assert jpg.startswith(_JPEG) |
|
85 | assert jpeg.startswith(_JPEG) | |
69 |
|
86 | |||
70 | def test_retina_figure(): |
|
87 | def test_retina_figure(): | |
71 | fig = plt.figure() |
|
88 | fig = plt.figure() |
General Comments 0
You need to be logged in to leave comments.
Login now