From 82630dedc2adc1f38192368404f5bfa2eba15a3a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 22 Jan 2017 02:16:58 -0500 Subject: [PATCH 1/5] Convert remaining tests to pytest. --- lib/matplotlib/__init__.py | 7 ------- lib/matplotlib/tests/test_coding_standards.py | 12 +++-------- lib/matplotlib/tests/test_image.py | 1 - lib/matplotlib/tests/test_legend.py | 5 ----- lib/matplotlib/tests/test_mlab.py | 10 --------- lib/matplotlib/tests/test_offsetbox.py | 9 ++------ lib/matplotlib/tests/test_patches.py | 13 +++--------- lib/matplotlib/tests/test_path.py | 12 ++++------- lib/matplotlib/tests/test_patheffects.py | 17 ++------------- lib/matplotlib/tests/test_pickle.py | 21 +++++++------------ lib/matplotlib/tests/test_quiver.py | 10 +++------ 11 files changed, 24 insertions(+), 93 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 65c449d9be03..f46af92e961c 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1474,14 +1474,7 @@ def _jupyter_nbextension_paths(): default_test_modules = [ - 'matplotlib.tests.test_coding_standards', - 'matplotlib.tests.test_offsetbox', - 'matplotlib.tests.test_patches', - 'matplotlib.tests.test_path', - 'matplotlib.tests.test_patheffects', - 'matplotlib.tests.test_pickle', 'matplotlib.tests.test_png', - 'matplotlib.tests.test_quiver', 'matplotlib.tests.test_units', 'matplotlib.tests.test_widgets', 'matplotlib.tests.test_cycles', diff --git a/lib/matplotlib/tests/test_coding_standards.py b/lib/matplotlib/tests/test_coding_standards.py index 671e5395aef4..8c1a8b08ee29 100644 --- a/lib/matplotlib/tests/test_coding_standards.py +++ b/lib/matplotlib/tests/test_coding_standards.py @@ -4,8 +4,7 @@ from fnmatch import fnmatch import os -from nose.tools import assert_equal -from nose.plugins.skip import SkipTest +import pytest from ..testing import xfail try: @@ -103,7 +102,7 @@ def assert_pep8_conformance(module=matplotlib, exclude_files=None, __tracebackhide__ = True if not HAS_PEP8: - raise SkipTest('The pep8 tool is required for this test') + pytest.skip('The pep8 tool is required for this test') # to get a list of bad files, rather than the specific errors, add # "reporter=pep8.FileReport" to the StyleGuide constructor. @@ -141,7 +140,7 @@ def assert_pep8_conformance(module=matplotlib, exclude_files=None, "{0}".format('\n'.join(reporter._global_deferred_print))) else: msg = "Found code syntax errors (and warnings)." - assert_equal(result.total_errors, 0, msg) + assert result.total_errors == 0, msg # If we've been using the exclusions reporter, check that we didn't # exclude files unnecessarily. @@ -287,8 +286,3 @@ def test_pep8_conformance_examples(): pep8_additional_ignore=PEP8_ADDITIONAL_IGNORE + ['E116', 'E501', 'E402'], expected_bad_files=expected_bad_files) - - -if __name__ == '__main__': - import nose - nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 382916662392..544fdf25b25e 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -6,7 +6,6 @@ import os import warnings - import numpy as np from numpy.testing import assert_array_equal diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 504c55da8313..fb36b19f8a4f 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -331,8 +331,3 @@ def test_linecollection_scaled_dashes(): for oh, lh in zip((lc1, lc2, lc3), (h1, h2, h3)): assert oh.get_linestyles()[0][1] == lh._dashSeq assert oh.get_linestyles()[0][0] == lh._dashOffset - - -if __name__ == '__main__': - import nose - nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tests/test_mlab.py b/lib/matplotlib/tests/test_mlab.py index a38f037d77db..0e438a506d6d 100644 --- a/lib/matplotlib/tests/test_mlab.py +++ b/lib/matplotlib/tests/test_mlab.py @@ -3102,13 +3102,3 @@ def test_psd_onesided_norm(): sides='onesided') Su_1side = np.append([Su[0]], Su[1:4] + Su[4:][::-1]) assert_allclose(P, Su_1side, atol=1e-06) - - -if __name__ == '__main__': - import nose - import sys - - args = ['-s', '--with-doctest'] - argv = sys.argv - argv = argv[:1] + args + argv[1:] - nose.runmodule(argv=argv, exit=False) diff --git a/lib/matplotlib/tests/test_offsetbox.py b/lib/matplotlib/tests/test_offsetbox.py index 076e7db83e8b..1eae1c2bdccb 100644 --- a/lib/matplotlib/tests/test_offsetbox.py +++ b/lib/matplotlib/tests/test_offsetbox.py @@ -1,8 +1,6 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) -import nose -from nose.tools import assert_true, assert_false from matplotlib.testing.decorators import image_comparison, cleanup import matplotlib.pyplot as plt import matplotlib.patches as mpatches @@ -78,9 +76,9 @@ def test_offsetbox_clip_children(): ax.add_artist(anchored_box) fig.canvas.draw() - assert_false(fig.stale) + assert not fig.stale da.clip_children = True - assert_true(fig.stale) + assert fig.stale @cleanup @@ -103,6 +101,3 @@ def test_offsetbox_loc_codes(): anchored_box = AnchoredOffsetbox(loc=code, child=da) ax.add_artist(anchored_box) fig.canvas.draw() - -if __name__ == '__main__': - nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 564dda5ab50d..8ebf10b431ab 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -7,9 +7,7 @@ import six import numpy as np -from numpy.testing import assert_array_equal -from numpy.testing import assert_equal -from numpy.testing import assert_almost_equal +from numpy.testing import assert_almost_equal, assert_array_equal from matplotlib.patches import Polygon from matplotlib.patches import Rectangle @@ -255,9 +253,9 @@ def test_wedge_movement(): w = mpatches.Wedge(**init_args) for attr, (old_v, new_v, func) in six.iteritems(param_dict): - assert_equal(getattr(w, attr), old_v) + assert getattr(w, attr) == old_v getattr(w, func)(new_v) - assert_equal(getattr(w, attr), new_v) + assert getattr(w, attr) == new_v # png needs tol>=0.06, pdf tol>=1.617 @@ -313,8 +311,3 @@ def test_patch_str(): p = mpatches.Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7) expected = 'Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)' assert str(p) == expected - - -if __name__ == '__main__': - import nose - nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index 6f1e57eed3d4..f57315e76528 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -7,10 +7,10 @@ import numpy as np from numpy.testing import assert_array_equal +import pytest from matplotlib.path import Path from matplotlib.patches import Polygon -from nose.tools import assert_raises, assert_equal from matplotlib.testing.decorators import image_comparison import matplotlib.pyplot as plt from matplotlib import transforms @@ -22,7 +22,8 @@ def test_readonly_path(): def modify_vertices(): path.vertices = path.vertices * 2.0 - assert_raises(AttributeError, modify_vertices) + with pytest.raises(AttributeError): + modify_vertices() def test_point_in_path(): @@ -90,7 +91,7 @@ def test_make_compound_path_empty(): # We should be able to make a compound path with no arguments. # This makes it easier to write generic path based code. r = Path.make_compound_path() - assert_equal(r.vertices.shape, (0, 2)) + assert r.vertices.shape == (0, 2) @image_comparison(baseline_images=['xkcd'], remove_text=True) @@ -181,8 +182,3 @@ def test_path_deepcopy(): path2 = Path(verts, codes) copy.deepcopy(path1) copy.deepcopy(path2) - - -if __name__ == '__main__': - import nose - nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tests/test_patheffects.py b/lib/matplotlib/tests/test_patheffects.py index b5ce1a7f68c6..5819f9b26a43 100644 --- a/lib/matplotlib/tests/test_patheffects.py +++ b/lib/matplotlib/tests/test_patheffects.py @@ -10,13 +10,6 @@ import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects -try: - # mock in python 3.3+ - from unittest import mock -except ImportError: - import mock -from nose.tools import assert_equal - @image_comparison(baseline_images=['patheffect1'], remove_text=True) def test_patheffect1(): @@ -101,13 +94,12 @@ def test_PathEffect_points_to_pixels(): # Confirm that using a path effects renderer maintains point sizes # appropriately. Otherwise rendered font would be the wrong size. - assert_equal(renderer.points_to_pixels(15), - pe_renderer.points_to_pixels(15)) + assert renderer.points_to_pixels(15) == pe_renderer.points_to_pixels(15) def test_SimplePatchShadow_offset(): pe = path_effects.SimplePatchShadow(offset=(4, 5)) - assert_equal(pe._offset, (4, 5)) + assert pe._offset == (4, 5) @image_comparison(baseline_images=['collection'], tol=0.015) @@ -127,8 +119,3 @@ def test_collection(): linewidth=3)]) text.set_bbox({'boxstyle': 'sawtooth', 'facecolor': 'none', 'edgecolor': 'blue'}) - - -if __name__ == '__main__': - import nose - nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tests/test_pickle.py b/lib/matplotlib/tests/test_pickle.py index 52d63c16b19e..f57d4f301538 100644 --- a/lib/matplotlib/tests/test_pickle.py +++ b/lib/matplotlib/tests/test_pickle.py @@ -7,7 +7,6 @@ from io import BytesIO -from nose.tools import assert_equal, assert_not_equal import numpy as np from matplotlib.testing.decorators import cleanup, image_comparison @@ -184,16 +183,16 @@ def test_complete(): plt.close('all') # make doubly sure that there are no figures left - assert_equal(plt._pylab_helpers.Gcf.figs, {}) + assert plt._pylab_helpers.Gcf.figs == {} # wind back the fh and load in the figure result_fh.seek(0) fig = pickle.load(result_fh) # make sure there is now a figure manager - assert_not_equal(plt._pylab_helpers.Gcf.figs, {}) + assert plt._pylab_helpers.Gcf.figs != {} - assert_equal(fig.get_label(), 'Figure with a label?') + assert fig.get_label() == 'Figure with a label?' @cleanup @@ -262,13 +261,12 @@ def test_transform(): obj = pickle.loads(pf) # Check parent -> child links of TransformWrapper. - assert_equal(obj.wrapper._child, obj.composite) + assert obj.wrapper._child == obj.composite # Check child -> parent links of TransformWrapper. - assert_equal( - [v() for v in obj.wrapper._parents.values()], [obj.composite2]) + assert [v() for v in obj.wrapper._parents.values()] == [obj.composite2] # Check input and output dimensions are set as expected. - assert_equal(obj.wrapper.input_dims, obj.composite.input_dims) - assert_equal(obj.wrapper.output_dims, obj.composite.output_dims) + assert obj.wrapper.input_dims == obj.composite.input_dims + assert obj.wrapper.output_dims == obj.composite.output_dims def test_rrulewrapper(): @@ -278,8 +276,3 @@ def test_rrulewrapper(): except RecursionError: print('rrulewrapper pickling test failed') raise - - -if __name__ == '__main__': - import nose - nose.runmodule(argv=['-s']) diff --git a/lib/matplotlib/tests/test_quiver.py b/lib/matplotlib/tests/test_quiver.py index eb60a0d918bd..fc7ddca0b38a 100644 --- a/lib/matplotlib/tests/test_quiver.py +++ b/lib/matplotlib/tests/test_quiver.py @@ -1,7 +1,7 @@ from __future__ import print_function import warnings import numpy as np -from nose.tools import raises +import pytest import sys from matplotlib import pyplot as plt from matplotlib.testing.decorators import cleanup @@ -149,7 +149,6 @@ def test_barbs(): @cleanup -@raises(ValueError) def test_bad_masked_sizes(): 'Test error handling when given differing sized masked arrays' x = np.arange(3) @@ -159,7 +158,8 @@ def test_bad_masked_sizes(): u[1] = np.ma.masked v[1] = np.ma.masked fig, ax = plt.subplots() - ax.barbs(x, y, u, v) + with pytest.raises(ValueError): + ax.barbs(x, y, u, v) @cleanup @@ -176,7 +176,3 @@ def test_quiverkey_angles(): # The arrows are only created when the key is drawn fig.canvas.draw() assert len(qk.verts) == 1 - -if __name__ == '__main__': - import nose - nose.runmodule() From 5f69c05a81fcb0f398d25612090788a57617f186 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 23 Jan 2017 16:18:04 -0500 Subject: [PATCH 2/5] Remove unused imports. --- lib/matplotlib/tests/test_image.py | 4 ++-- lib/matplotlib/tests/test_path.py | 2 -- lib/matplotlib/tests/test_patheffects.py | 2 -- lib/matplotlib/tests/test_pickle.py | 10 +++++----- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 544fdf25b25e..dad4f9ba3408 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -11,8 +11,8 @@ from matplotlib.testing.decorators import (image_comparison, knownfailureif, cleanup) -from matplotlib.image import (BboxImage, imread, NonUniformImage, - AxesImage, FigureImage, PcolorImage) +from matplotlib.image import (AxesImage, BboxImage, FigureImage, + NonUniformImage, PcolorImage) from matplotlib.transforms import Bbox, Affine2D, TransformedBbox from matplotlib import rcParams, rc_context from matplotlib import patches diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index f57315e76528..c29289ae81f2 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -2,8 +2,6 @@ unicode_literals) import copy -import six - import numpy as np from numpy.testing import assert_array_equal diff --git a/lib/matplotlib/tests/test_patheffects.py b/lib/matplotlib/tests/test_patheffects.py index 5819f9b26a43..4417347c854a 100644 --- a/lib/matplotlib/tests/test_patheffects.py +++ b/lib/matplotlib/tests/test_patheffects.py @@ -1,8 +1,6 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) -import six - import numpy as np from matplotlib.testing.decorators import (image_comparison, cleanup, diff --git a/lib/matplotlib/tests/test_pickle.py b/lib/matplotlib/tests/test_pickle.py index f57d4f301538..9d59ad8b8349 100644 --- a/lib/matplotlib/tests/test_pickle.py +++ b/lib/matplotlib/tests/test_pickle.py @@ -3,7 +3,7 @@ import six from six.moves import cPickle as pickle -from six.moves import xrange +from six.moves import range from io import BytesIO @@ -104,7 +104,7 @@ def test_simple(): pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL) ax = plt.axes(projection='polar') - plt.plot(list(xrange(10)), label='foobar') + plt.plot(np.arange(10), label='foobar') plt.legend() # Uncomment to debug any unpicklable objects. This is slow so is not @@ -117,12 +117,12 @@ def test_simple(): # pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL) plt.figure() - plt.bar(left=list(xrange(10)), height=list(xrange(10))) + plt.bar(left=np.arange(10), height=np.arange(10)) pickle.dump(plt.gca(), BytesIO(), pickle.HIGHEST_PROTOCOL) fig = plt.figure() ax = plt.axes() - plt.plot(list(xrange(10))) + plt.plot(np.arange(10)) ax.set_yscale('log') pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL) @@ -140,7 +140,7 @@ def test_complete(): v = np.sin(v * -0.6) plt.subplot(3, 3, 1) - plt.plot(list(xrange(10))) + plt.plot(list(range(10))) # Ensure lists also pickle correctly. plt.subplot(3, 3, 2) plt.contourf(data, hatches=['//', 'ooo']) From c2d301b21b4c5eb576a5b5ec712644b4b6874b09 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 23 Jan 2017 16:59:50 -0500 Subject: [PATCH 3/5] Stop modifying default_test_modules in pytest build. --- conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/conftest.py b/conftest.py index 2a1dbe0a4ece..4a149112416f 100644 --- a/conftest.py +++ b/conftest.py @@ -69,7 +69,6 @@ def pytest_configure(config): matplotlib._init_tests() if config.getoption('--no-pep8'): - default_test_modules.remove('matplotlib.tests.test_coding_standards') IGNORED_TESTS['matplotlib'] += 'test_coding_standards' From 00448293897e4c39dda45e62f77dd461458aa9c1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 23 Jan 2017 17:18:31 -0500 Subject: [PATCH 4/5] Remove another default_test_modules modification. --- tests.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests.py b/tests.py index 01c48d0d8f35..a05d2b129db3 100755 --- a/tests.py +++ b/tests.py @@ -14,7 +14,7 @@ if __name__ == '__main__': - from matplotlib import default_test_modules, test + from matplotlib import test parser = argparse.ArgumentParser(add_help=False) parser.add_argument('--no-pep8', action='store_true', @@ -27,10 +27,6 @@ help='Shortcut for specifying number of test processes') args, extra_args = parser.parse_known_args() - if args.no_pep8: - default_test_modules.remove('matplotlib.tests.test_coding_standards') - elif args.pep8: - default_test_modules[:] = ['matplotlib.tests.test_coding_standards'] if args.no_network: from matplotlib.testing import disable_internet disable_internet.turn_off_internet() From dda6023aee43ab6094c83c6a4ab941e32c3a6984 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 23 Jan 2017 17:38:41 -0500 Subject: [PATCH 5/5] Replace np.testing.assert_raises with pytest.raises. The former requires nose. --- lib/matplotlib/__init__.py | 1 - lib/matplotlib/tests/test_colors.py | 12 ++++---- lib/matplotlib/tests/test_contour.py | 7 +++-- lib/matplotlib/tests/test_cycles.py | 42 +++++++++++++++++----------- lib/matplotlib/tests/test_dates.py | 20 ++++++++----- lib/matplotlib/tests/test_lines.py | 6 ++-- 6 files changed, 51 insertions(+), 37 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index f46af92e961c..8f829dc68847 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1477,7 +1477,6 @@ def _jupyter_nbextension_paths(): 'matplotlib.tests.test_png', 'matplotlib.tests.test_units', 'matplotlib.tests.test_widgets', - 'matplotlib.tests.test_cycles', ] diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index c066797f90d1..ca341e74cf42 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -8,7 +8,7 @@ import numpy as np -from numpy.testing import assert_raises, assert_equal +from numpy.testing import assert_equal from numpy.testing.utils import assert_array_equal, assert_array_almost_equal from matplotlib import cycler @@ -336,7 +336,8 @@ def test_cmap_and_norm_from_levels_and_colors2(): 'Wih extend={0!r} and data ' 'value={1!r}'.format(extend, d_val)) - assert_raises(ValueError, mcolors.from_levels_and_colors, levels, colors) + with pytest.raises(ValueError): + mcolors.from_levels_and_colors(levels, colors) def test_rgb_hsv_round_trip(): @@ -359,11 +360,8 @@ def test_autoscale_masked(): def test_colors_no_float(): # Gray must be a string to distinguish 3-4 grays from RGB or RGBA. - - def gray_from_float_rgba(): - return mcolors.to_rgba(0.4) - - assert_raises(ValueError, gray_from_float_rgba) + with pytest.raises(ValueError): + mcolors.to_rgba(0.4) @image_comparison(baseline_images=['light_source_shading_topo'], diff --git a/lib/matplotlib/tests/test_contour.py b/lib/matplotlib/tests/test_contour.py index 9e0ae90cc0ab..21efd9ddf495 100644 --- a/lib/matplotlib/tests/test_contour.py +++ b/lib/matplotlib/tests/test_contour.py @@ -7,8 +7,8 @@ from matplotlib import mlab from matplotlib.testing.decorators import cleanup, image_comparison from matplotlib import pyplot as plt -from numpy.testing import assert_equal, assert_raises from numpy.testing import assert_array_almost_equal +import pytest import warnings import re @@ -282,13 +282,14 @@ def test_contourf_decreasing_levels(): # github issue 5477. z = [[0.1, 0.3], [0.5, 0.7]] plt.figure() - assert_raises(ValueError, plt.contourf, z, [1.0, 0.0]) + with pytest.raises(ValueError): + plt.contourf(z, [1.0, 0.0]) # Legacy contouring algorithm gives a warning rather than raising an error, # plus a DeprecationWarning. with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") plt.contourf(z, [1.0, 0.0], corner_mask='legacy') - assert_equal(len(w), 2) + assert len(w) == 2 @cleanup diff --git a/lib/matplotlib/tests/test_cycles.py b/lib/matplotlib/tests/test_cycles.py index 6e9fb5025fb3..7e84c55e8eb0 100644 --- a/lib/matplotlib/tests/test_cycles.py +++ b/lib/matplotlib/tests/test_cycles.py @@ -4,7 +4,7 @@ from matplotlib.cbook import MatplotlibDeprecationWarning import matplotlib.pyplot as plt import numpy as np -from numpy.testing import assert_raises +import pytest from cycler import cycler @@ -198,18 +198,28 @@ def test_cycle_reset(): @cleanup def test_invalid_input_forms(): fig, ax = plt.subplots() - assert_raises((TypeError, ValueError), ax.set_prop_cycle, 1) - assert_raises((TypeError, ValueError), ax.set_prop_cycle, [1, 2]) - assert_raises((TypeError, ValueError), ax.set_prop_cycle, 'color', 'fish') - assert_raises((TypeError, ValueError), ax.set_prop_cycle, 'linewidth', 1) - assert_raises((TypeError, ValueError), ax.set_prop_cycle, - 'linewidth', {'1': 1, '2': 2}) - assert_raises((TypeError, ValueError), ax.set_prop_cycle, - linewidth=1, color='r') - assert_raises((TypeError, ValueError), ax.set_prop_cycle, 'foobar', [1, 2]) - assert_raises((TypeError, ValueError), ax.set_prop_cycle, - foobar=[1, 2]) - assert_raises((TypeError, ValueError), ax.set_prop_cycle, - cycler(foobar=[1, 2])) - assert_raises(ValueError, ax.set_prop_cycle, - cycler(color='rgb', c='cmy')) + + with pytest.raises((TypeError, ValueError)): + ax.set_prop_cycle(1) + with pytest.raises((TypeError, ValueError)): + ax.set_prop_cycle([1, 2]) + + with pytest.raises((TypeError, ValueError)): + ax.set_prop_cycle('color', 'fish') + + with pytest.raises((TypeError, ValueError)): + ax.set_prop_cycle('linewidth', 1) + with pytest.raises((TypeError, ValueError)): + ax.set_prop_cycle('linewidth', {'1': 1, '2': 2}) + with pytest.raises((TypeError, ValueError)): + ax.set_prop_cycle(linewidth=1, color='r') + + with pytest.raises((TypeError, ValueError)): + ax.set_prop_cycle('foobar', [1, 2]) + with pytest.raises((TypeError, ValueError)): + ax.set_prop_cycle(foobar=[1, 2]) + + with pytest.raises((TypeError, ValueError)): + ax.set_prop_cycle(cycler(foobar=[1, 2])) + with pytest.raises(ValueError): + ax.set_prop_cycle(cycler(color='rgb', c='cmy')) diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 377e66efb006..8108ecb6045d 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -17,7 +17,7 @@ except ImportError: import mock -from numpy.testing import assert_raises, assert_equal +from numpy.testing import assert_equal from matplotlib.testing.decorators import image_comparison, cleanup import matplotlib.pyplot as plt @@ -108,7 +108,8 @@ def test_too_many_date_ticks(): ax.set_xlim((t0, tf), auto=True) ax.plot([], []) ax.xaxis.set_major_locator(mdates.DayLocator()) - assert_raises(RuntimeError, fig.savefig, 'junk.png') + with pytest.raises(RuntimeError): + fig.savefig('junk.png') @image_comparison(baseline_images=['RRuleLocator_bounds'], extensions=['png']) @@ -266,7 +267,8 @@ def test_empty_date_with_year_formatter(): ax.xaxis.set_major_formatter(yearFmt) with tempfile.TemporaryFile() as fh: - assert_raises(ValueError, fig.savefig, fh) + with pytest.raises(ValueError): + fig.savefig(fh) def test_auto_date_locator(): @@ -453,10 +455,14 @@ def tz_convert(*args): def test_DayLocator(): - assert_raises(ValueError, mdates.DayLocator, interval=-1) - assert_raises(ValueError, mdates.DayLocator, interval=-1.5) - assert_raises(ValueError, mdates.DayLocator, interval=0) - assert_raises(ValueError, mdates.DayLocator, interval=1.3) + with pytest.raises(ValueError): + mdates.DayLocator(interval=-1) + with pytest.raises(ValueError): + mdates.DayLocator(interval=-1.5) + with pytest.raises(ValueError): + mdates.DayLocator(interval=0) + with pytest.raises(ValueError): + mdates.DayLocator(interval=1.3) mdates.DayLocator(interval=1.0) diff --git a/lib/matplotlib/tests/test_lines.py b/lib/matplotlib/tests/test_lines.py index 9fd416e1433a..58405a707ecd 100644 --- a/lib/matplotlib/tests/test_lines.py +++ b/lib/matplotlib/tests/test_lines.py @@ -6,7 +6,7 @@ import itertools import matplotlib.lines as mlines -from numpy.testing import assert_raises +import pytest from timeit import repeat import numpy as np from cycler import cycler @@ -109,7 +109,7 @@ def test_linestyle_variants(): @cleanup def test_valid_linestyles(): line = mlines.Line2D([], []) - with assert_raises(ValueError): + with pytest.raises(ValueError): line.set_linestyle('aardvark') @@ -130,7 +130,7 @@ def test_drawstyle_variants(): @cleanup def test_valid_drawstyles(): line = mlines.Line2D([], []) - with assert_raises(ValueError): + with pytest.raises(ValueError): line.set_drawstyle('foobar')