From d700f039a6f10ffb795c59467fa62bfde8aa162d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 30 Jan 2017 00:05:56 -0500 Subject: [PATCH 1/2] Parametrize colormap reversing test. This is a bit nicer for debugging. --- lib/matplotlib/tests/test_colors.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index 41480a77cbde..8d2000bd511a 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -608,19 +608,19 @@ def test_pandas_iterable(): assert_array_equal(cm1.colors, cm2.colors) -def test_colormap_reversing(): +@pytest.mark.parametrize('name', cm.cmap_d) +def test_colormap_reversing(name): """Check the generated _lut data of a colormap and corresponding reversed colormap if they are almost the same.""" - for name in cm.cmap_d: - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - cmap = plt.get_cmap(name) - assert len(w) == (1 if name in ('spectral', 'spectral_r') else 0) - cmap_r = cmap.reversed() - if not cmap_r._isinit: - cmap._init() - cmap_r._init() - assert_array_almost_equal(cmap._lut[:-3], cmap_r._lut[-4::-1]) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + cmap = plt.get_cmap(name) + assert len(w) == (1 if name in ('spectral', 'spectral_r') else 0) + cmap_r = cmap.reversed() + if not cmap_r._isinit: + cmap._init() + cmap_r._init() + assert_array_almost_equal(cmap._lut[:-3], cmap_r._lut[-4::-1]) @cleanup From 2bd330db78dae041286479c5cdb62d21645b933f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 30 Jan 2017 00:07:29 -0500 Subject: [PATCH 2/2] Add Vega* colormaps to warning check in test. --- lib/matplotlib/tests/test_colors.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index 8d2000bd511a..30e0964aa299 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -612,10 +612,13 @@ def test_pandas_iterable(): def test_colormap_reversing(name): """Check the generated _lut data of a colormap and corresponding reversed colormap if they are almost the same.""" + should_have_warning = {'spectral', 'spectral_r', 'Vega10', 'Vega10_r', + 'Vega20', 'Vega20_r', 'Vega20b', 'Vega20b_r', + 'Vega20c', 'Vega20c_r'} with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') cmap = plt.get_cmap(name) - assert len(w) == (1 if name in ('spectral', 'spectral_r') else 0) + assert len(w) == (1 if name in should_have_warning else 0) cmap_r = cmap.reversed() if not cmap_r._isinit: cmap._init()