|
| 1 | +from datetime import datetime |
1 | 2 | import io |
| 3 | +import re |
2 | 4 | from types import SimpleNamespace |
3 | | -from datetime import datetime |
4 | 5 |
|
5 | 6 | import numpy as np |
6 | 7 | from numpy.testing import assert_array_equal, assert_array_almost_equal |
@@ -817,36 +818,38 @@ def test_quadmesh_set_array_validation(): |
817 | 818 | fig, ax = plt.subplots() |
818 | 819 | coll = ax.pcolormesh(x, y, z) |
819 | 820 |
|
820 | | - # Test deprecated warning when faulty shape is passed. |
821 | | - with pytest.raises(ValueError, match=r"For X \(11\) and Y \(8\) with flat " |
822 | | - r"shading, the expected shape of A is \(7, 10\), not " |
823 | | - r"\(10, 7\)"): |
| 821 | + with pytest.raises(ValueError, match=re.escape( |
| 822 | + "For X (11) and Y (8) with flat shading, A should have shape " |
| 823 | + "(7, 10, 3) or (7, 10, 4) or (7, 10) or (70,), not (10, 7)")): |
824 | 824 | coll.set_array(z.reshape(10, 7)) |
825 | 825 |
|
826 | 826 | z = np.arange(54).reshape((6, 9)) |
827 | | - with pytest.raises(TypeError, match=r"Dimensions of A \(6, 9\) " |
828 | | - r"are incompatible with X \(11\) and/or Y \(8\)"): |
| 827 | + with pytest.raises(ValueError, match=re.escape( |
| 828 | + "For X (11) and Y (8) with flat shading, A should have shape " |
| 829 | + "(7, 10, 3) or (7, 10, 4) or (7, 10) or (70,), not (6, 9)")): |
829 | 830 | coll.set_array(z) |
830 | | - with pytest.raises(TypeError, match=r"Dimensions of A \(54,\) " |
831 | | - r"are incompatible with X \(11\) and/or Y \(8\)"): |
| 831 | + with pytest.raises(ValueError, match=re.escape( |
| 832 | + "For X (11) and Y (8) with flat shading, A should have shape " |
| 833 | + "(7, 10, 3) or (7, 10, 4) or (7, 10) or (70,), not (54,)")): |
832 | 834 | coll.set_array(z.ravel()) |
833 | 835 |
|
834 | 836 | # RGB(A) tests |
835 | 837 | z = np.ones((9, 6, 3)) # RGB with wrong X/Y dims |
836 | | - with pytest.raises(TypeError, match=r"Dimensions of A \(9, 6, 3\) " |
837 | | - r"are incompatible with X \(11\) and/or Y \(8\)"): |
| 838 | + with pytest.raises(ValueError, match=re.escape( |
| 839 | + "For X (11) and Y (8) with flat shading, A should have shape " |
| 840 | + "(7, 10, 3) or (7, 10, 4) or (7, 10) or (70,), not (9, 6, 3)")): |
838 | 841 | coll.set_array(z) |
839 | 842 |
|
840 | 843 | z = np.ones((9, 6, 4)) # RGBA with wrong X/Y dims |
841 | | - with pytest.raises(TypeError, match=r"Dimensions of A \(9, 6, 4\) " |
842 | | - r"are incompatible with X \(11\) and/or Y \(8\)"): |
| 844 | + with pytest.raises(ValueError, match=re.escape( |
| 845 | + "For X (11) and Y (8) with flat shading, A should have shape " |
| 846 | + "(7, 10, 3) or (7, 10, 4) or (7, 10) or (70,), not (9, 6, 4)")): |
843 | 847 | coll.set_array(z) |
844 | 848 |
|
845 | 849 | z = np.ones((7, 10, 2)) # Right X/Y dims, bad 3rd dim |
846 | | - with pytest.raises(ValueError, match=r"For X \(11\) and Y \(8\) with " |
847 | | - r"flat shading, the expected shape of " |
848 | | - r"A with RGB\(A\) colors is \(7, 10, \[3 or 4\]\), " |
849 | | - r"not \(7, 10, 2\)"): |
| 850 | + with pytest.raises(ValueError, match=re.escape( |
| 851 | + "For X (11) and Y (8) with flat shading, A should have shape " |
| 852 | + "(7, 10, 3) or (7, 10, 4) or (7, 10) or (70,), not (7, 10, 2)")): |
850 | 853 | coll.set_array(z) |
851 | 854 |
|
852 | 855 | x = np.arange(10) |
|
0 commit comments