Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36a3f7f

Browse files
committed
added tests for the sketch param validator
1 parent c486c95 commit 36a3f7f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lib/matplotlib/tests/test_rcparams.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
validate_int,
2828
validate_markevery,
2929
validate_stringlist,
30+
validate_sketch,
3031
_validate_linestyle,
3132
_listify_validator)
3233

@@ -628,3 +629,38 @@ def test_rcparams_legend_loc_from_file(tmpdir, value):
628629

629630
with mpl.rc_context(fname=rc_path):
630631
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

Comments
 (0)