|
27 | 27 | validate_int,
|
28 | 28 | validate_markevery,
|
29 | 29 | validate_stringlist,
|
| 30 | + validate_sketch, |
30 | 31 | _validate_linestyle,
|
31 | 32 | _listify_validator)
|
32 | 33 |
|
@@ -628,3 +629,38 @@ def test_rcparams_legend_loc_from_file(tmpdir, value):
|
628 | 629 |
|
629 | 630 | with mpl.rc_context(fname=rc_path):
|
630 | 631 | assert mpl.rcParams["legend.loc"] == value
|
| 632 | + |
| 633 | + |
| 634 | +@pytest.mark.parametrize("value", [(1, 2, 3), '1, 2, 3']) |
| 635 | +def test_validate_sketch(value): |
| 636 | + mpl.rcParams["path.sketch"] = value |
| 637 | + assert mpl.rcParams["path.sketch"] == (1, 2, 3) |
| 638 | + assert validate_sketch(value) == (1, 2, 3) |
| 639 | + |
| 640 | + |
| 641 | +@pytest.mark.parametrize("value", [1, '1', '(1, 2, 3)']) |
| 642 | +def test_validate_sketch_error(value): |
| 643 | + with pytest.raises(ValueError, match="'scale, length, randomness'"): |
| 644 | + validate_sketch(value) |
| 645 | + with pytest.raises(ValueError, match="'scale, length, randomness'"): |
| 646 | + mpl.rcParams["path.sketch"] = value |
| 647 | + |
| 648 | + |
| 649 | +def test_rcparams_path_sketch_from_file(tmpdir): |
| 650 | + rc_path = tmpdir.join("matplotlibrc") |
| 651 | + rc_path.write("path.sketch: 1, 2, 3") |
| 652 | + |
| 653 | + with mpl.rc_context(fname=rc_path): |
| 654 | + assert mpl.rcParams["path.sketch"] == (1, 2, 3) |
| 655 | + |
| 656 | + |
| 657 | +def test_rcparams_path_sketch_from_file_error(tmpdir, caplog): |
| 658 | + # rcParams parser doesn't read a tuple rcfile entry |
| 659 | + rc_path = tmpdir.join("matplotlibrc") |
| 660 | + rc_path.write("path.sketch: (1, 2, 3)") |
| 661 | + |
| 662 | + with mpl.rc_context(fname=rc_path): |
| 663 | + with caplog.at_level("WARNING"): |
| 664 | + assert mpl.rcParams['path.sketch'] is None |
| 665 | + assert ("Expected a 'scale, length, randomness' triplet" |
| 666 | + in caplog.text) |
0 commit comments