Blob Blame History Raw
From 279f95dae9dcd74d51c5913254889712697d1d8a Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Fri, 6 Oct 2017 20:06:09 -0400
Subject: [PATCH 2/8] TST: Capture all internal warnings.

These are either deprecations, or checks for old, but probably
incorrect, behaviour.

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
 lib/matplotlib/tests/test_axes.py   | 10 ++++++++--
 lib/matplotlib/tests/test_cbook.py  | 22 ++++++++++++----------
 lib/matplotlib/tests/test_colors.py | 10 +++++++++-
 lib/matplotlib/tests/test_dates.py  |  5 ++++-
 lib/matplotlib/tests/test_image.py  |  4 ++--
 5 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py
index 0c22740a4..273b6f4ec 100644
--- a/lib/matplotlib/tests/test_axes.py
+++ b/lib/matplotlib/tests/test_axes.py
@@ -1677,13 +1677,19 @@ def test_as_mpl_axes_api():
     ax_via_gca = plt.gca(projection=prj)
     assert ax_via_gca is ax
     # try getting the axes given a different polar projection
-    ax_via_gca = plt.gca(projection=prj2)
+    with pytest.warns(UserWarning) as rec:
+        ax_via_gca = plt.gca(projection=prj2)
+        assert len(rec) == 1
+        assert 'Requested projection is different' in str(rec[0].message)
     assert ax_via_gca is not ax
     assert ax.get_theta_offset() == 0, ax.get_theta_offset()
     assert ax_via_gca.get_theta_offset() == np.pi, \
         ax_via_gca.get_theta_offset()
     # try getting the axes given an == (not is) polar projection
-    ax_via_gca = plt.gca(projection=prj3)
+    with pytest.warns(UserWarning):
+        ax_via_gca = plt.gca(projection=prj3)
+        assert len(rec) == 1
+        assert 'Requested projection is different' in str(rec[0].message)
     assert ax_via_gca is ax
     plt.close()
 
diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py
index f254b173c..4ff2cc52a 100644
--- a/lib/matplotlib/tests/test_cbook.py
+++ b/lib/matplotlib/tests/test_cbook.py
@@ -29,16 +29,18 @@ def test_is_hashable():
 
 def test_restrict_dict():
     d = {'foo': 'bar', 1: 2}
-    d1 = cbook.restrict_dict(d, ['foo', 1])
-    assert d1 == d
-    d2 = cbook.restrict_dict(d, ['bar', 2])
-    assert d2 == {}
-    d3 = cbook.restrict_dict(d, {'foo': 1})
-    assert d3 == {'foo': 'bar'}
-    d4 = cbook.restrict_dict(d, {})
-    assert d4 == {}
-    d5 = cbook.restrict_dict(d, {'foo', 2})
-    assert d5 == {'foo': 'bar'}
+    with pytest.warns(cbook.deprecation.MatplotlibDeprecationWarning) as rec:
+        d1 = cbook.restrict_dict(d, ['foo', 1])
+        assert d1 == d
+        d2 = cbook.restrict_dict(d, ['bar', 2])
+        assert d2 == {}
+        d3 = cbook.restrict_dict(d, {'foo': 1})
+        assert d3 == {'foo': 'bar'}
+        d4 = cbook.restrict_dict(d, {})
+        assert d4 == {}
+        d5 = cbook.restrict_dict(d, {'foo', 2})
+        assert d5 == {'foo': 'bar'}
+    assert len(rec) == 5
     # check that d was not modified
     assert d == {'foo': 'bar', 1: 2}
 
diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py
index 721813e62..82c73fe71 100644
--- a/lib/matplotlib/tests/test_colors.py
+++ b/lib/matplotlib/tests/test_colors.py
@@ -690,7 +690,7 @@ def test_tableau_order():
     assert list(mcolors.TABLEAU_COLORS.values()) == dflt_cycle
 
 
-def test_ndarray_subclass_norm():
+def test_ndarray_subclass_norm(recwarn):
     # Emulate an ndarray subclass that handles units
     # which objects when adding or subtracting with other
     # arrays. See #6622 and #8696
@@ -707,3 +707,11 @@ def test_ndarray_subclass_norm():
                  mcolors.SymLogNorm(3, vmax=5, linscale=1),
                  mcolors.PowerNorm(1)]:
         assert_array_equal(norm(data.view(MyArray)), norm(data))
+        if isinstance(norm, mcolors.PowerNorm):
+            assert len(recwarn) == 1
+            warn = recwarn.pop(UserWarning)
+            assert ('Power-law scaling on negative values is ill-defined'
+                    in str(warn.message))
+        else:
+            assert len(recwarn) == 0
+        recwarn.clear()
diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py
index 9f69d2ea7..437482f5f 100644
--- a/lib/matplotlib/tests/test_dates.py
+++ b/lib/matplotlib/tests/test_dates.py
@@ -96,7 +96,10 @@ def test_too_many_date_ticks():
     tf = datetime.datetime(2000, 1, 20)
     fig = plt.figure()
     ax = fig.add_subplot(1, 1, 1)
-    ax.set_xlim((t0, tf), auto=True)
+    with pytest.warns(UserWarning) as rec:
+        ax.set_xlim((t0, tf), auto=True)
+        assert len(rec) == 1
+        assert 'Attempting to set identical left==right' in str(rec[0].message)
     ax.plot([], [])
     ax.xaxis.set_major_locator(mdates.DayLocator())
     with pytest.raises(RuntimeError):
diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py
index 68a22894e..6240dd219 100644
--- a/lib/matplotlib/tests/test_image.py
+++ b/lib/matplotlib/tests/test_image.py
@@ -603,7 +603,8 @@ def test_load_from_url():
 
 @image_comparison(baseline_images=['log_scale_image'],
                   remove_text=True)
-def test_log_scale_image():
+# The recwarn fixture captures a warning in image_comparison.
+def test_log_scale_image(recwarn):
     Z = np.zeros((10, 10))
     Z[::2] = 1
 
@@ -615,7 +616,6 @@ def test_log_scale_image():
     ax.set_yscale('log')
 
 
-
 @image_comparison(baseline_images=['rotate_image'],
                   remove_text=True)
 def test_rotate_image():
-- 
2.13.5