|
12 | 12 | from matplotlib import _api, _c_internal_utils |
13 | 13 | import matplotlib.pyplot as plt |
14 | 14 | import matplotlib.colors as mcolors |
| 15 | +import matplotlib.patheffects as path_effects |
| 16 | +from matplotlib.testing.decorators import check_figures_equal |
| 17 | + |
15 | 18 | import numpy as np |
16 | 19 | from matplotlib.rcsetup import ( |
17 | 20 | validate_bool, |
|
28 | 31 | validate_markevery, |
29 | 32 | validate_stringlist, |
30 | 33 | _validate_linestyle, |
31 | | - _listify_validator) |
| 34 | + validate_anydict, |
| 35 | + _listify_validator, |
| 36 | + ) |
32 | 37 |
|
33 | 38 |
|
34 | 39 | def test_rcparams(tmpdir): |
@@ -628,3 +633,35 @@ def test_rcparams_legend_loc_from_file(tmpdir, value): |
628 | 633 |
|
629 | 634 | with mpl.rc_context(fname=rc_path): |
630 | 635 | assert mpl.rcParams["legend.loc"] == value |
| 636 | + |
| 637 | + |
| 638 | +@pytest.mark.parametrize("allow_none", [True, False]) |
| 639 | +def test_validate_dict(allow_none): |
| 640 | + fval = validate_anydict(allow_none) |
| 641 | + assert fval("{'a':1, 'b':2}") == {'a': 1, 'b': 2} |
| 642 | + with pytest.raises(ValueError, match=r"Input \['a', 'b'\] "): |
| 643 | + fval(['a', 'b']) |
| 644 | + |
| 645 | + |
| 646 | +def test_validate_dict_none(): |
| 647 | + assert validate_anydict()(None) is None |
| 648 | + with pytest.raises(ValueError, |
| 649 | + match=r"Input None must be a dictionary "): |
| 650 | + validate_anydict(False)(None) |
| 651 | + with pytest.raises(ValueError, |
| 652 | + match=r"Input 0 must be a dictionary {'k': v} or None"): |
| 653 | + validate_anydict(True)(0) |
| 654 | + |
| 655 | + |
| 656 | +def test_path_effects(): |
| 657 | + mpl.rcParams['path.effects.withStroke'] = {'linewidth': 4} |
| 658 | + assert mpl.rcParams['path.effects.withStroke'] == {'linewidth': 4} |
| 659 | + |
| 660 | + |
| 661 | +@check_figures_equal() |
| 662 | +def test_path_effects_specific(fig_test, fig_ref): |
| 663 | + with mpl.rc_context({'path.effects.withStroke': {'linewidth': 4}}): |
| 664 | + fig_test.subplots().plot([1, 2, 3]) |
| 665 | + |
| 666 | + with mpl.rc_context({'path.effects': [path_effects.withStroke(linewidth=4)]}): |
| 667 | + fig_ref.subplots().plot([1, 2, 3]) |
0 commit comments