|
| 1 | +import contextlib |
1 | 2 | from collections import namedtuple |
2 | 3 | import datetime |
3 | 4 | from decimal import Decimal |
@@ -2638,15 +2639,18 @@ def get_next_color(): |
2638 | 2639 | "conversion": "^'c' argument must be a color", # bad vals |
2639 | 2640 | } |
2640 | 2641 |
|
2641 | | - if re_key is None: |
| 2642 | + |
| 2643 | + assert_context = ( |
| 2644 | + pytest.raises(ValueError, match=REGEXP[re_key]) |
| 2645 | + if re_key is not None |
| 2646 | + else pytest.warns(match="argument looks like a single numeric RGB") |
| 2647 | + if isinstance(c_case, list) and len(c_case) == 3 |
| 2648 | + else contextlib.nullcontext() |
| 2649 | + ) |
| 2650 | + with assert_context: |
2642 | 2651 | mpl.axes.Axes._parse_scatter_color_args( |
2643 | 2652 | c=c_case, edgecolors="black", kwargs={}, xsize=xsize, |
2644 | 2653 | get_next_color_func=get_next_color) |
2645 | | - else: |
2646 | | - with pytest.raises(ValueError, match=REGEXP[re_key]): |
2647 | | - mpl.axes.Axes._parse_scatter_color_args( |
2648 | | - c=c_case, edgecolors="black", kwargs={}, xsize=xsize, |
2649 | | - get_next_color_func=get_next_color) |
2650 | 2654 |
|
2651 | 2655 | @mpl.style.context('default') |
2652 | 2656 | @check_figures_equal(extensions=["png"]) |
@@ -6803,9 +6807,9 @@ def test_color_length_mismatch(): |
6803 | 6807 | fig, ax = plt.subplots() |
6804 | 6808 | with pytest.raises(ValueError): |
6805 | 6809 | ax.scatter(x, y, c=colors) |
6806 | | - c_rgb = (0.5, 0.5, 0.5) |
6807 | | - ax.scatter(x, y, c=c_rgb) |
6808 | | - ax.scatter(x, y, c=[c_rgb] * N) |
| 6810 | + with pytest.warns(match="argument looks like a single numeric RGB"): |
| 6811 | + ax.scatter(x, y, c=(0.5, 0.5, 0.5)) |
| 6812 | + ax.scatter(x, y, c=[(0.5, 0.5, 0.5)] * N) |
6809 | 6813 |
|
6810 | 6814 |
|
6811 | 6815 | def test_eventplot_legend(): |
@@ -7688,7 +7692,8 @@ def test_2dcolor_plot(fig_test, fig_ref): |
7688 | 7692 | # plot with 1D-color: |
7689 | 7693 | axs = fig_test.subplots(5) |
7690 | 7694 | axs[0].plot([1, 2], [1, 2], c=color.reshape(-1)) |
7691 | | - axs[1].scatter([1, 2], [1, 2], c=color.reshape(-1)) |
| 7695 | + with pytest.warns(match="argument looks like a single numeric RGB"): |
| 7696 | + axs[1].scatter([1, 2], [1, 2], c=color.reshape(-1)) |
7692 | 7697 | axs[2].step([1, 2], [1, 2], c=color.reshape(-1)) |
7693 | 7698 | axs[3].hist(np.arange(10), color=color.reshape(-1)) |
7694 | 7699 | axs[4].bar(np.arange(10), np.arange(10), color=color.reshape(-1)) |
|
0 commit comments