|
15 | 15 | assert_array_almost_equal) |
16 | 16 | import pytest |
17 | 17 |
|
| 18 | +import matplotlib as mpl |
18 | 19 | from matplotlib import _api, cbook |
19 | 20 | import matplotlib.colors as mcolors |
20 | 21 | from matplotlib.cbook import delete_masked_points, strip_math |
@@ -480,30 +481,42 @@ def test_resize_sequence(): |
480 | 481 | assert_array_equal(cbook._resize_sequence(arr, 5), [1, 2, 3, 1, 2]) |
481 | 482 |
|
482 | 483 |
|
483 | | -fail_mapping: tuple[tuple[dict, dict], ...] = ( |
484 | | - ({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['b']}}), |
485 | | - ({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['a', 'b']}}), |
486 | | -) |
| 484 | +fail_mapping: list[tuple[dict, dict]] = [ |
| 485 | + ({"a": 1, "b": 2}, {"a": ["b"]}), |
| 486 | + ({"a": 1, "b": 2}, {"a": ["a", "b"]}), |
| 487 | +] |
487 | 488 |
|
488 | | -pass_mapping: tuple[tuple[Any, dict, dict], ...] = ( |
| 489 | +pass_mapping: list[tuple[Any, dict, dict]] = [ |
489 | 490 | (None, {}, {}), |
490 | | - ({'a': 1, 'b': 2}, {'a': 1, 'b': 2}, {}), |
491 | | - ({'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}), |
492 | | -) |
| 491 | + ({"a": 1, "b": 2}, {"a": 1, "b": 2}, {}), |
| 492 | + ({"b": 2}, {"a": 2}, {"a": ["a", "b"]}), |
| 493 | +] |
493 | 494 |
|
494 | 495 |
|
495 | | -@pytest.mark.parametrize('inp, kwargs_to_norm', fail_mapping) |
496 | | -def test_normalize_kwargs_fail(inp, kwargs_to_norm): |
497 | | - with pytest.raises(TypeError), _api.suppress_matplotlib_deprecation_warning(): |
498 | | - cbook.normalize_kwargs(inp, **kwargs_to_norm) |
| 496 | +@pytest.mark.parametrize('inp, alias_def', fail_mapping) |
| 497 | +def test_normalize_kwargs_fail(inp, alias_def): |
499 | 498 |
|
| 499 | + @_api.define_aliases(alias_def) |
| 500 | + class Type(mpl.artist.Artist): |
| 501 | + def get_a(self): return None |
500 | 502 |
|
501 | | -@pytest.mark.parametrize('inp, expected, kwargs_to_norm', |
502 | | - pass_mapping) |
503 | | -def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm): |
504 | | - with _api.suppress_matplotlib_deprecation_warning(): |
505 | | - # No other warning should be emitted. |
506 | | - assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm) |
| 503 | + with pytest.raises(TypeError): |
| 504 | + cbook.normalize_kwargs(inp, Type) |
| 505 | + |
| 506 | + |
| 507 | +@pytest.mark.parametrize('inp, expected, alias_def', pass_mapping) |
| 508 | +def test_normalize_kwargs_pass(inp, expected, alias_def): |
| 509 | + |
| 510 | + @_api.define_aliases(alias_def) |
| 511 | + class Type(mpl.artist.Artist): |
| 512 | + def get_a(self): return None |
| 513 | + |
| 514 | + assert expected == cbook.normalize_kwargs(inp, Type) |
| 515 | + old_alias_map = {} |
| 516 | + for alias, prop in Type._alias_to_prop.items(): |
| 517 | + old_alias_map.setdefault(prop, []).append(alias) |
| 518 | + with pytest.warns(mpl.MatplotlibDeprecationWarning): |
| 519 | + assert expected == cbook.normalize_kwargs(inp, old_alias_map) |
507 | 520 |
|
508 | 521 |
|
509 | 522 | def test_warn_external(recwarn): |
|
0 commit comments