Show More
@@ -751,7 +751,7 def set_matplotlib_formats(*formats, **kwargs): | |||||
751 | select_figure_formats(shell, formats, **kw) |
|
751 | select_figure_formats(shell, formats, **kw) | |
752 |
|
752 | |||
753 | @skip_doctest |
|
753 | @skip_doctest | |
754 | def set_matplotlib_close(close): |
|
754 | def set_matplotlib_close(close=True): | |
755 | """Set whether the inline backend closes all figures automatically or not. |
|
755 | """Set whether the inline backend closes all figures automatically or not. | |
756 |
|
756 | |||
757 | By default, the inline backend used in the IPython Notebook will close all |
|
757 | By default, the inline backend used in the IPython Notebook will close all | |
@@ -772,7 +772,7 def set_matplotlib_close(close): | |||||
772 | Should all matplotlib figures be automatically closed after each cell is |
|
772 | Should all matplotlib figures be automatically closed after each cell is | |
773 | run? |
|
773 | run? | |
774 | """ |
|
774 | """ | |
775 |
from IPython.kernel.zmq.pylab. |
|
775 | from IPython.kernel.zmq.pylab.config import InlineBackend | |
776 |
|
|
776 | cfg = InlineBackend.instance() | |
777 |
|
|
777 | cfg.close_figures = close | |
778 |
|
778 |
@@ -10,8 +10,11 import os | |||||
10 | import nose.tools as nt |
|
10 | import nose.tools as nt | |
11 |
|
11 | |||
12 | from IPython.core import display |
|
12 | from IPython.core import display | |
|
13 | from IPython.core.getipython import get_ipython | |||
13 | from IPython.utils import path as ipath |
|
14 | from IPython.utils import path as ipath | |
14 |
|
15 | |||
|
16 | import IPython.testing.decorators as dec | |||
|
17 | ||||
15 | def test_image_size(): |
|
18 | def test_image_size(): | |
16 | """Simple test for display.Image(args, width=x,height=y)""" |
|
19 | """Simple test for display.Image(args, width=x,height=y)""" | |
17 | thisurl = 'http://www.google.fr/images/srpr/logo3w.png' |
|
20 | thisurl = 'http://www.google.fr/images/srpr/logo3w.png' | |
@@ -58,3 +61,58 def test_image_filename_defaults(): | |||||
58 | img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False) |
|
61 | img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False) | |
59 | nt.assert_equal('jpeg', img.format) |
|
62 | nt.assert_equal('jpeg', img.format) | |
60 | nt.assert_is_none(img._repr_jpeg_()) |
|
63 | nt.assert_is_none(img._repr_jpeg_()) | |
|
64 | ||||
|
65 | def _get_inline_config(): | |||
|
66 | from IPython.kernel.zmq.pylab.config import InlineBackend | |||
|
67 | return InlineBackend.instance() | |||
|
68 | ||||
|
69 | @dec.skip_without('matplotlib') | |||
|
70 | def test_set_matplotlib_close(): | |||
|
71 | cfg = _get_inline_config() | |||
|
72 | cfg.close_figures = False | |||
|
73 | display.set_matplotlib_close() | |||
|
74 | assert cfg.close_figures | |||
|
75 | display.set_matplotlib_close(False) | |||
|
76 | assert not cfg.close_figures | |||
|
77 | ||||
|
78 | _fmt_mime_map = { | |||
|
79 | 'png': 'image/png', | |||
|
80 | 'jpeg': 'image/jpeg', | |||
|
81 | 'pdf': 'application/pdf', | |||
|
82 | 'retina': 'image/png', | |||
|
83 | 'svg': 'image/svg+xml', | |||
|
84 | } | |||
|
85 | ||||
|
86 | @dec.skip_without('matplotlib') | |||
|
87 | def test_set_matplotlib_formats(): | |||
|
88 | from matplotlib.figure import Figure | |||
|
89 | formatters = get_ipython().display_formatter.formatters | |||
|
90 | for formats in [ | |||
|
91 | ('png',), | |||
|
92 | ('pdf', 'svg'), | |||
|
93 | ('jpeg', 'retina', 'png'), | |||
|
94 | (), | |||
|
95 | ]: | |||
|
96 | active_mimes = {_fmt_mime_map[fmt] for fmt in formats} | |||
|
97 | display.set_matplotlib_formats(*formats) | |||
|
98 | for mime, f in formatters.items(): | |||
|
99 | if mime in active_mimes: | |||
|
100 | nt.assert_in(Figure, f) | |||
|
101 | else: | |||
|
102 | nt.assert_not_in(Figure, f) | |||
|
103 | ||||
|
104 | @dec.skip_without('matplotlib') | |||
|
105 | def test_set_matplotlib_formats_kwargs(): | |||
|
106 | from matplotlib.figure import Figure | |||
|
107 | ip = get_ipython() | |||
|
108 | cfg = _get_inline_config() | |||
|
109 | cfg.print_figure_kwargs.update(dict(foo='bar')) | |||
|
110 | kwargs = dict(quality=10) | |||
|
111 | display.set_matplotlib_formats('png', **kwargs) | |||
|
112 | formatter = ip.display_formatter.formatters['image/png'] | |||
|
113 | f = formatter.lookup_by_type(Figure) | |||
|
114 | cell = f.__closure__[0].cell_contents | |||
|
115 | expected = kwargs | |||
|
116 | expected.update(cfg.print_figure_kwargs) | |||
|
117 | nt.assert_equal(cell, expected) | |||
|
118 |
General Comments 0
You need to be logged in to leave comments.
Login now