diff --git a/IPython/core/tests/test_pylabtools.py b/IPython/core/tests/test_pylabtools.py index 426930d..64acd3d 100644 --- a/IPython/core/tests/test_pylabtools.py +++ b/IPython/core/tests/test_pylabtools.py @@ -12,12 +12,10 @@ import matplotlib matplotlib.use('Agg') from matplotlib.figure import Figure -from nose import SkipTest -import nose.tools as nt - from matplotlib import pyplot as plt -import matplotlib_inline +from matplotlib_inline import backend_inline import numpy as np +import pytest from IPython.core.getipython import get_ipython from IPython.core.interactiveshell import InteractiveShell @@ -30,7 +28,7 @@ from IPython.testing import decorators as dec def test_figure_to_svg(): # simple empty-figure test fig = plt.figure() - nt.assert_equal(pt.print_figure(fig, 'svg'), None) + assert pt.print_figure(fig, "svg") is None plt.close('all') @@ -39,8 +37,9 @@ def test_figure_to_svg(): ax = fig.add_subplot(1,1,1) ax.plot([1,2,3]) plt.draw() - svg = pt.print_figure(fig, 'svg')[:100].lower() - nt.assert_in(u'doctype svg', svg) + svg = pt.print_figure(fig, "svg")[:100].lower() + assert "doctype svg" in svg + def _check_pil_jpeg_bytes(): """Skip if PIL can't write JPEGs to BytesIO objects""" @@ -53,7 +52,7 @@ def _check_pil_jpeg_bytes(): img.save(buf, 'jpeg') except Exception as e: ename = e.__class__.__name__ - raise SkipTest("PIL can't write JPEG to BytesIO: %s: %s" % (ename, e)) from e + raise pytest.skip("PIL can't write JPEG to BytesIO: %s: %s" % (ename, e)) from e @dec.skip_without("PIL.Image") def test_figure_to_jpeg(): @@ -69,7 +68,7 @@ def test_figure_to_jpeg(): def test_retina_figure(): # simple empty-figure test fig = plt.figure() - nt.assert_equal(pt.retina_figure(fig), None) + assert pt.retina_figure(fig) == None plt.close('all') fig = plt.figure() @@ -78,8 +77,9 @@ def test_retina_figure(): plt.draw() png, md = pt.retina_figure(fig) assert png.startswith(_PNG) - nt.assert_in('width', md) - nt.assert_in('height', md) + assert "width" in md + assert "height" in md + _fmt_mime_map = { 'png': 'image/png', @@ -95,9 +95,9 @@ def test_select_figure_formats_str(): pt.select_figure_formats(ip, fmt) for mime, f in ip.display_formatter.formatters.items(): if mime == active_mime: - nt.assert_in(Figure, f) + assert Figure in f else: - nt.assert_not_in(Figure, f) + assert Figure not in f def test_select_figure_formats_kwargs(): ip = get_ipython() @@ -134,24 +134,25 @@ def test_select_figure_formats_set(): pt.select_figure_formats(ip, fmts) for mime, f in ip.display_formatter.formatters.items(): if mime in active_mimes: - nt.assert_in(Figure, f) + assert Figure in f else: - nt.assert_not_in(Figure, f) + assert Figure not in f def test_select_figure_formats_bad(): ip = get_ipython() - with nt.assert_raises(ValueError): + with pytest.raises(ValueError): pt.select_figure_formats(ip, 'foo') - with nt.assert_raises(ValueError): + with pytest.raises(ValueError): pt.select_figure_formats(ip, {'png', 'foo'}) - with nt.assert_raises(ValueError): + with pytest.raises(ValueError): pt.select_figure_formats(ip, ['retina', 'pdf', 'bar', 'bad']) def test_import_pylab(): ns = {} pt.import_pylab(ns, import_all=False) - nt.assert_true('plt' in ns) - nt.assert_equal(ns['np'], np) + assert "plt" in ns + assert ns["np"] == np + from traitlets.config import Config @@ -182,15 +183,13 @@ class TestPylabSwitch(object): pt.activate_matplotlib = act_mpl self._save_ip = pt.import_pylab pt.import_pylab = lambda *a,**kw:None - self._save_cis = matplotlib_inline.backend_inline.configure_inline_support - matplotlib_inline.backend_inline.configure_inline_support = ( - lambda *a, **kw: None - ) + self._save_cis = backend_inline.configure_inline_support + backend_inline.configure_inline_support = lambda *a, **kw: None def teardown(self): pt.activate_matplotlib = self._save_am pt.import_pylab = self._save_ip - matplotlib_inline.backend_inline.configure_inline_support = self._save_cis + backend_inline.configure_inline_support = self._save_cis import matplotlib matplotlib.rcParams = self._saved_rcParams matplotlib.rcParamsOrig = self._saved_rcParamsOrig @@ -199,68 +198,68 @@ class TestPylabSwitch(object): s = self.Shell() gui, backend = s.enable_matplotlib(None) - nt.assert_equal(gui, 'qt') - nt.assert_equal(s.pylab_gui_select, 'qt') + assert gui == "qt" + assert s.pylab_gui_select == "qt" - gui, backend = s.enable_matplotlib('inline') - nt.assert_equal(gui, 'inline') - nt.assert_equal(s.pylab_gui_select, 'qt') + gui, backend = s.enable_matplotlib("inline") + assert gui == "inline" + assert s.pylab_gui_select == "qt" - gui, backend = s.enable_matplotlib('qt') - nt.assert_equal(gui, 'qt') - nt.assert_equal(s.pylab_gui_select, 'qt') + gui, backend = s.enable_matplotlib("qt") + assert gui == "qt" + assert s.pylab_gui_select == "qt" - gui, backend = s.enable_matplotlib('inline') - nt.assert_equal(gui, 'inline') - nt.assert_equal(s.pylab_gui_select, 'qt') + gui, backend = s.enable_matplotlib("inline") + assert gui == "inline" + assert s.pylab_gui_select == "qt" gui, backend = s.enable_matplotlib() - nt.assert_equal(gui, 'qt') - nt.assert_equal(s.pylab_gui_select, 'qt') + assert gui == "qt" + assert s.pylab_gui_select == "qt" def test_inline(self): s = self.Shell() - gui, backend = s.enable_matplotlib('inline') - nt.assert_equal(gui, 'inline') - nt.assert_equal(s.pylab_gui_select, None) + gui, backend = s.enable_matplotlib("inline") + assert gui == "inline" + assert s.pylab_gui_select == None - gui, backend = s.enable_matplotlib('inline') - nt.assert_equal(gui, 'inline') - nt.assert_equal(s.pylab_gui_select, None) + gui, backend = s.enable_matplotlib("inline") + assert gui == "inline" + assert s.pylab_gui_select == None - gui, backend = s.enable_matplotlib('qt') - nt.assert_equal(gui, 'qt') - nt.assert_equal(s.pylab_gui_select, 'qt') + gui, backend = s.enable_matplotlib("qt") + assert gui == "qt" + assert s.pylab_gui_select == "qt" def test_inline_twice(self): "Using '%matplotlib inline' twice should not reset formatters" ip = self.Shell() - gui, backend = ip.enable_matplotlib('inline') - nt.assert_equal(gui, 'inline') + gui, backend = ip.enable_matplotlib("inline") + assert gui == "inline" fmts = {'png'} active_mimes = {_fmt_mime_map[fmt] for fmt in fmts} pt.select_figure_formats(ip, fmts) - gui, backend = ip.enable_matplotlib('inline') - nt.assert_equal(gui, 'inline') + gui, backend = ip.enable_matplotlib("inline") + assert gui == "inline" for mime, f in ip.display_formatter.formatters.items(): if mime in active_mimes: - nt.assert_in(Figure, f) + assert Figure in f else: - nt.assert_not_in(Figure, f) + assert Figure not in f def test_qt_gtk(self): s = self.Shell() - gui, backend = s.enable_matplotlib('qt') - nt.assert_equal(gui, 'qt') - nt.assert_equal(s.pylab_gui_select, 'qt') + gui, backend = s.enable_matplotlib("qt") + assert gui == "qt" + assert s.pylab_gui_select == "qt" - gui, backend = s.enable_matplotlib('gtk') - nt.assert_equal(gui, 'qt') - nt.assert_equal(s.pylab_gui_select, 'qt') + gui, backend = s.enable_matplotlib("gtk") + assert gui == "qt" + assert s.pylab_gui_select == "qt" def test_no_gui_backends():