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

Skip to content

Commit 1c67ded

Browse files
author
MKhadra
committed
Added validator tests to test_rcparams and renamed validator function in rcsetup.py
1 parent 5458309 commit 1c67ded

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def validate_hatch(s):
792792
validate_dashlist = _listify_validator(validate_nseq_float(allow_none=True))
793793

794794

795-
def validate_minor_tick_ndivs(n):
795+
def validate_int_or_auto(n):
796796
"""
797797
Validate the given ndiv parameter for minor ticks.
798798
ndiv can be either the string 'auto' or a non-negative integer.
@@ -1352,7 +1352,7 @@ def _convert_validator_spec(key, conv):
13521352
'xtick.minor.bottom': [True, validate_bool], # draw x axis bottom minor ticks
13531353
'xtick.major.top': [True, validate_bool], # draw x axis top major ticks
13541354
'xtick.major.bottom': [True, validate_bool], # draw x axis bottom major ticks
1355-
'xtick.minor.ndivs': ['auto', validate_minor_tick_ndivs], # default number of minor ticks to display between each pair of major ticks
1355+
'xtick.minor.ndivs': ['auto', validate_int_or_auto], # default number of minor ticks to display between each pair of major ticks
13561356

13571357
# fontsize of the xtick labels
13581358
'xtick.labelsize': ['medium', validate_fontsize],
@@ -1376,7 +1376,7 @@ def _convert_validator_spec(key, conv):
13761376
'ytick.minor.right': [True, validate_bool], # draw y axis right minor ticks
13771377
'ytick.major.left': [True, validate_bool], # draw y axis left major ticks
13781378
'ytick.major.right': [True, validate_bool], # draw y axis right major ticks
1379-
'ytick.minor.ndivs': ['auto', validate_minor_tick_ndivs], # default number of minor ticks to display between each pair of major ticks
1379+
'ytick.minor.ndivs': ['auto', validate_int_or_auto], # default number of minor ticks to display between each pair of major ticks
13801380

13811381
# fontsize of the ytick labels
13821382
'ytick.labelsize': ['medium', validate_fontsize],

lib/matplotlib/tests/test_rcparams.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
validate_hatch,
2727
validate_hist_bins,
2828
validate_markevery,
29-
_validate_linestyle)
29+
_validate_linestyle,
30+
validate_int_or_auto)
3031

3132

3233
def test_rcparams(tmpdir):
@@ -387,6 +388,16 @@ def generate_validator_testcases(valid):
387388
(([1, 2], 1), ValueError), # inverted offset/onoff
388389
)
389390
},
391+
{'validator': validate_int_or_auto,
392+
'success': ((3, 3),
393+
(100, 100),
394+
(0, 0),
395+
('auto', 'auto')
396+
),
397+
'fail': (('random string', ValueError), # not a valid string
398+
(-100, RuntimeError) # not a valid int
399+
)
400+
},
390401
)
391402

392403
for validator_dict in validation_tests:

0 commit comments

Comments
 (0)