Show More
@@ -12,12 +12,10 b' import matplotlib' | |||
|
12 | 12 | matplotlib.use('Agg') |
|
13 | 13 | from matplotlib.figure import Figure |
|
14 | 14 | |
|
15 | from nose import SkipTest | |
|
16 | import nose.tools as nt | |
|
17 | ||
|
18 | 15 | from matplotlib import pyplot as plt |
|
19 | import matplotlib_inline | |
|
16 | from matplotlib_inline import backend_inline | |
|
20 | 17 | import numpy as np |
|
18 | import pytest | |
|
21 | 19 | |
|
22 | 20 | from IPython.core.getipython import get_ipython |
|
23 | 21 | from IPython.core.interactiveshell import InteractiveShell |
@@ -30,7 +28,7 b' from IPython.testing import decorators as dec' | |||
|
30 | 28 | def test_figure_to_svg(): |
|
31 | 29 | # simple empty-figure test |
|
32 | 30 | fig = plt.figure() |
|
33 |
|
|
|
31 | assert pt.print_figure(fig, "svg") is None | |
|
34 | 32 | |
|
35 | 33 | plt.close('all') |
|
36 | 34 | |
@@ -39,8 +37,9 b' def test_figure_to_svg():' | |||
|
39 | 37 | ax = fig.add_subplot(1,1,1) |
|
40 | 38 | ax.plot([1,2,3]) |
|
41 | 39 | plt.draw() |
|
42 |
svg = pt.print_figure(fig, |
|
|
43 |
|
|
|
40 | svg = pt.print_figure(fig, "svg")[:100].lower() | |
|
41 | assert "doctype svg" in svg | |
|
42 | ||
|
44 | 43 | |
|
45 | 44 | def _check_pil_jpeg_bytes(): |
|
46 | 45 | """Skip if PIL can't write JPEGs to BytesIO objects""" |
@@ -53,7 +52,7 b' def _check_pil_jpeg_bytes():' | |||
|
53 | 52 | img.save(buf, 'jpeg') |
|
54 | 53 | except Exception as e: |
|
55 | 54 | ename = e.__class__.__name__ |
|
56 |
raise |
|
|
55 | raise pytest.skip("PIL can't write JPEG to BytesIO: %s: %s" % (ename, e)) from e | |
|
57 | 56 | |
|
58 | 57 | @dec.skip_without("PIL.Image") |
|
59 | 58 | def test_figure_to_jpeg(): |
@@ -69,7 +68,7 b' def test_figure_to_jpeg():' | |||
|
69 | 68 | def test_retina_figure(): |
|
70 | 69 | # simple empty-figure test |
|
71 | 70 | fig = plt.figure() |
|
72 |
|
|
|
71 | assert pt.retina_figure(fig) == None | |
|
73 | 72 | plt.close('all') |
|
74 | 73 | |
|
75 | 74 | fig = plt.figure() |
@@ -78,8 +77,9 b' def test_retina_figure():' | |||
|
78 | 77 | plt.draw() |
|
79 | 78 | png, md = pt.retina_figure(fig) |
|
80 | 79 | assert png.startswith(_PNG) |
|
81 |
|
|
|
82 |
|
|
|
80 | assert "width" in md | |
|
81 | assert "height" in md | |
|
82 | ||
|
83 | 83 | |
|
84 | 84 | _fmt_mime_map = { |
|
85 | 85 | 'png': 'image/png', |
@@ -95,9 +95,9 b' def test_select_figure_formats_str():' | |||
|
95 | 95 | pt.select_figure_formats(ip, fmt) |
|
96 | 96 | for mime, f in ip.display_formatter.formatters.items(): |
|
97 | 97 | if mime == active_mime: |
|
98 |
|
|
|
98 | assert Figure in f | |
|
99 | 99 | else: |
|
100 |
|
|
|
100 | assert Figure not in f | |
|
101 | 101 | |
|
102 | 102 | def test_select_figure_formats_kwargs(): |
|
103 | 103 | ip = get_ipython() |
@@ -134,24 +134,25 b' def test_select_figure_formats_set():' | |||
|
134 | 134 | pt.select_figure_formats(ip, fmts) |
|
135 | 135 | for mime, f in ip.display_formatter.formatters.items(): |
|
136 | 136 | if mime in active_mimes: |
|
137 |
|
|
|
137 | assert Figure in f | |
|
138 | 138 | else: |
|
139 |
|
|
|
139 | assert Figure not in f | |
|
140 | 140 | |
|
141 | 141 | def test_select_figure_formats_bad(): |
|
142 | 142 | ip = get_ipython() |
|
143 |
with |
|
|
143 | with pytest.raises(ValueError): | |
|
144 | 144 | pt.select_figure_formats(ip, 'foo') |
|
145 |
with |
|
|
145 | with pytest.raises(ValueError): | |
|
146 | 146 | pt.select_figure_formats(ip, {'png', 'foo'}) |
|
147 |
with |
|
|
147 | with pytest.raises(ValueError): | |
|
148 | 148 | pt.select_figure_formats(ip, ['retina', 'pdf', 'bar', 'bad']) |
|
149 | 149 | |
|
150 | 150 | def test_import_pylab(): |
|
151 | 151 | ns = {} |
|
152 | 152 | pt.import_pylab(ns, import_all=False) |
|
153 |
|
|
|
154 |
|
|
|
153 | assert "plt" in ns | |
|
154 | assert ns["np"] == np | |
|
155 | ||
|
155 | 156 | |
|
156 | 157 | from traitlets.config import Config |
|
157 | 158 | |
@@ -182,15 +183,13 b' class TestPylabSwitch(object):' | |||
|
182 | 183 | pt.activate_matplotlib = act_mpl |
|
183 | 184 | self._save_ip = pt.import_pylab |
|
184 | 185 | pt.import_pylab = lambda *a,**kw:None |
|
185 |
self._save_cis = |
|
|
186 |
|
|
|
187 | lambda *a, **kw: None | |
|
188 | ) | |
|
186 | self._save_cis = backend_inline.configure_inline_support | |
|
187 | backend_inline.configure_inline_support = lambda *a, **kw: None | |
|
189 | 188 | |
|
190 | 189 | def teardown(self): |
|
191 | 190 | pt.activate_matplotlib = self._save_am |
|
192 | 191 | pt.import_pylab = self._save_ip |
|
193 |
|
|
|
192 | backend_inline.configure_inline_support = self._save_cis | |
|
194 | 193 | import matplotlib |
|
195 | 194 | matplotlib.rcParams = self._saved_rcParams |
|
196 | 195 | matplotlib.rcParamsOrig = self._saved_rcParamsOrig |
@@ -199,68 +198,68 b' class TestPylabSwitch(object):' | |||
|
199 | 198 | |
|
200 | 199 | s = self.Shell() |
|
201 | 200 | gui, backend = s.enable_matplotlib(None) |
|
202 |
|
|
|
203 |
|
|
|
201 | assert gui == "qt" | |
|
202 | assert s.pylab_gui_select == "qt" | |
|
204 | 203 | |
|
205 |
gui, backend = s.enable_matplotlib( |
|
|
206 |
|
|
|
207 |
|
|
|
204 | gui, backend = s.enable_matplotlib("inline") | |
|
205 | assert gui == "inline" | |
|
206 | assert s.pylab_gui_select == "qt" | |
|
208 | 207 | |
|
209 |
gui, backend = s.enable_matplotlib( |
|
|
210 |
|
|
|
211 |
|
|
|
208 | gui, backend = s.enable_matplotlib("qt") | |
|
209 | assert gui == "qt" | |
|
210 | assert s.pylab_gui_select == "qt" | |
|
212 | 211 | |
|
213 |
gui, backend = s.enable_matplotlib( |
|
|
214 |
|
|
|
215 |
|
|
|
212 | gui, backend = s.enable_matplotlib("inline") | |
|
213 | assert gui == "inline" | |
|
214 | assert s.pylab_gui_select == "qt" | |
|
216 | 215 | |
|
217 | 216 | gui, backend = s.enable_matplotlib() |
|
218 |
|
|
|
219 |
|
|
|
217 | assert gui == "qt" | |
|
218 | assert s.pylab_gui_select == "qt" | |
|
220 | 219 | |
|
221 | 220 | def test_inline(self): |
|
222 | 221 | s = self.Shell() |
|
223 |
gui, backend = s.enable_matplotlib( |
|
|
224 |
|
|
|
225 |
|
|
|
222 | gui, backend = s.enable_matplotlib("inline") | |
|
223 | assert gui == "inline" | |
|
224 | assert s.pylab_gui_select == None | |
|
226 | 225 | |
|
227 |
gui, backend = s.enable_matplotlib( |
|
|
228 |
|
|
|
229 |
|
|
|
226 | gui, backend = s.enable_matplotlib("inline") | |
|
227 | assert gui == "inline" | |
|
228 | assert s.pylab_gui_select == None | |
|
230 | 229 | |
|
231 |
gui, backend = s.enable_matplotlib( |
|
|
232 |
|
|
|
233 |
|
|
|
230 | gui, backend = s.enable_matplotlib("qt") | |
|
231 | assert gui == "qt" | |
|
232 | assert s.pylab_gui_select == "qt" | |
|
234 | 233 | |
|
235 | 234 | def test_inline_twice(self): |
|
236 | 235 | "Using '%matplotlib inline' twice should not reset formatters" |
|
237 | 236 | |
|
238 | 237 | ip = self.Shell() |
|
239 |
gui, backend = ip.enable_matplotlib( |
|
|
240 |
|
|
|
238 | gui, backend = ip.enable_matplotlib("inline") | |
|
239 | assert gui == "inline" | |
|
241 | 240 | |
|
242 | 241 | fmts = {'png'} |
|
243 | 242 | active_mimes = {_fmt_mime_map[fmt] for fmt in fmts} |
|
244 | 243 | pt.select_figure_formats(ip, fmts) |
|
245 | 244 | |
|
246 |
gui, backend = ip.enable_matplotlib( |
|
|
247 |
|
|
|
245 | gui, backend = ip.enable_matplotlib("inline") | |
|
246 | assert gui == "inline" | |
|
248 | 247 | |
|
249 | 248 | for mime, f in ip.display_formatter.formatters.items(): |
|
250 | 249 | if mime in active_mimes: |
|
251 |
|
|
|
250 | assert Figure in f | |
|
252 | 251 | else: |
|
253 |
|
|
|
252 | assert Figure not in f | |
|
254 | 253 | |
|
255 | 254 | def test_qt_gtk(self): |
|
256 | 255 | s = self.Shell() |
|
257 |
gui, backend = s.enable_matplotlib( |
|
|
258 |
|
|
|
259 |
|
|
|
256 | gui, backend = s.enable_matplotlib("qt") | |
|
257 | assert gui == "qt" | |
|
258 | assert s.pylab_gui_select == "qt" | |
|
260 | 259 | |
|
261 |
gui, backend = s.enable_matplotlib( |
|
|
262 |
|
|
|
263 |
|
|
|
260 | gui, backend = s.enable_matplotlib("gtk") | |
|
261 | assert gui == "qt" | |
|
262 | assert s.pylab_gui_select == "qt" | |
|
264 | 263 | |
|
265 | 264 | |
|
266 | 265 | def test_no_gui_backends(): |
General Comments 0
You need to be logged in to leave comments.
Login now