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

Skip to content

Commit 243ed19

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

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
@@ -783,7 +783,7 @@ def validate_hatch(s):
783783
validate_dashlist = _listify_validator(validate_nseq_float(allow_none=True))
784784

785785

786-
def validate_minor_tick_ndivs(n):
786+
def validate_int_or_auto(n):
787787
"""
788788
Validate the given ndiv parameter for minor ticks.
789789
ndiv can be either the string 'auto' or a non-negative integer.
@@ -1344,7 +1344,7 @@ def _convert_validator_spec(key, conv):
13441344
'xtick.minor.bottom': [True, validate_bool], # draw x axis bottom minor ticks
13451345
'xtick.major.top': [True, validate_bool], # draw x axis top major ticks
13461346
'xtick.major.bottom': [True, validate_bool], # draw x axis bottom major ticks
1347-
'xtick.minor.ndivs': ['auto', validate_minor_tick_ndivs], # default number of minor ticks to display between each pair of major ticks
1347+
'xtick.minor.ndivs': ['auto', validate_int_or_auto], # default number of minor ticks to display between each pair of major ticks
13481348

13491349
# fontsize of the xtick labels
13501350
'xtick.labelsize': ['medium', validate_fontsize],
@@ -1368,7 +1368,7 @@ def _convert_validator_spec(key, conv):
13681368
'ytick.minor.right': [True, validate_bool], # draw y axis right minor ticks
13691369
'ytick.major.left': [True, validate_bool], # draw y axis left major ticks
13701370
'ytick.major.right': [True, validate_bool], # draw y axis right major ticks
1371-
'ytick.minor.ndivs': ['auto', validate_minor_tick_ndivs], # default number of minor ticks to display between each pair of major ticks
1371+
'ytick.minor.ndivs': ['auto', validate_int_or_auto], # default number of minor ticks to display between each pair of major ticks
13721372

13731373
# fontsize of the ytick labels
13741374
'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):
@@ -393,6 +394,16 @@ def generate_validator_testcases(valid):
393394
(([1, 2], 1), ValueError), # inverted offset/onoff
394395
)
395396
},
397+
{'validator': validate_int_or_auto,
398+
'success': ((3, 3),
399+
(100, 100),
400+
(0, 0),
401+
('auto', 'auto')
402+
),
403+
'fail': (('random string', ValueError), # not a valid string
404+
(-100, RuntimeError) # not a valid int
405+
)
406+
},
396407
)
397408

398409
for validator_dict in validation_tests:

0 commit comments

Comments
 (0)