-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Rcparam validation fix #3564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jenshnielsen
merged 19 commits into
matplotlib:v1.4.x
from
tacaswell:rcparam_validation_fix
Oct 14, 2014
Merged
Rcparam validation fix #3564
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5c9ccf0
MNT : make sure to cast to unicode
tacaswell ec7276c
BUG : make rcParams.update validates inputs
tacaswell a298ab2
MNT : simplify and relax validation on nseq
tacaswell 8602912
BUG : validate_stringlist should drop empty strings
tacaswell 31fe5e0
BUG : give animation args valid default values
tacaswell 30eaa0b
TST : minor tweaks to animation smoketests
tacaswell 1c2bc58
TST : added tests for some validation functions
tacaswell 1f06313
BUG : validate input on the way into rcparams
tacaswell a88f5dd
TST : tests to make sure rcparams get validated
tacaswell 0aa2fcd
TST : skip the fail tests on 2.6
tacaswell d9ab665
MNT : no deprecated rcparams in RcParamDefault
tacaswell 99e3be3
TST : add cleanup decorators to some tests
tacaswell c93041c
MNT : re-work obsolete_rcparams
tacaswell 962793b
TST : known fail more tests on 2.6
tacaswell b7e0719
TST : special case pathexists for None
tacaswell 4cc899c
BUG : fixed string list default values
tacaswell f1f5795
ENH : change failed validations into warnings
tacaswell d8fb745
TST : known-fail rcparam exceptions tests
tacaswell 726495e
TST : added test that keymap values are all lists
tacaswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,8 @@ def validate_any(s): | |
|
||
def validate_path_exists(s): | ||
"""If s is a path, return s, else False""" | ||
if s is None: | ||
return None | ||
if os.path.exists(s): | ||
return s | ||
else: | ||
|
@@ -172,50 +174,54 @@ def validate_maskedarray(v): | |
' please delete it from your matplotlibrc file') | ||
|
||
|
||
class validate_nseq_float: | ||
_seq_err_msg = ('You must supply exactly {n:d} values, you provided ' | ||
'{num:d} values: {s}') | ||
|
||
_str_err_msg = ('You must supply exactly {n:d} comma-separated values, ' | ||
'you provided ' | ||
'{num:d} comma-separated values: {s}') | ||
|
||
|
||
class validate_nseq_float(object): | ||
def __init__(self, n): | ||
self.n = n | ||
|
||
def __call__(self, s): | ||
"""return a seq of n floats or raise""" | ||
if isinstance(s, six.string_types): | ||
ss = s.split(',') | ||
if len(ss) != self.n: | ||
raise ValueError( | ||
'You must supply exactly %d comma separated values' % | ||
self.n) | ||
try: | ||
return [float(val) for val in ss] | ||
except ValueError: | ||
raise ValueError('Could not convert all entries to floats') | ||
s = s.split(',') | ||
err_msg = _str_err_msg | ||
else: | ||
assert type(s) in (list, tuple) | ||
if len(s) != self.n: | ||
raise ValueError('You must supply exactly %d values' % self.n) | ||
err_msg = _seq_err_msg | ||
|
||
if len(s) != self.n: | ||
raise ValueError(err_msg.format(n=self.n, num=len(s), s=s)) | ||
|
||
try: | ||
return [float(val) for val in s] | ||
except ValueError: | ||
raise ValueError('Could not convert all entries to floats') | ||
|
||
|
||
class validate_nseq_int: | ||
class validate_nseq_int(object): | ||
def __init__(self, n): | ||
self.n = n | ||
|
||
def __call__(self, s): | ||
"""return a seq of n ints or raise""" | ||
if isinstance(s, six.string_types): | ||
ss = s.split(',') | ||
if len(ss) != self.n: | ||
raise ValueError( | ||
'You must supply exactly %d comma separated values' % | ||
self.n) | ||
try: | ||
return [int(val) for val in ss] | ||
except ValueError: | ||
raise ValueError('Could not convert all entries to ints') | ||
s = s.split(',') | ||
err_msg = _str_err_msg | ||
else: | ||
assert type(s) in (list, tuple) | ||
if len(s) != self.n: | ||
raise ValueError('You must supply exactly %d values' % self.n) | ||
err_msg = _seq_err_msg | ||
|
||
if len(s) != self.n: | ||
raise ValueError(err_msg.format(n=self.n, num=len(s), s=s)) | ||
|
||
try: | ||
return [int(val) for val in s] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Time for some factorisation? This is class is exactly the same as the float version, except for the |
||
except ValueError: | ||
raise ValueError('Could not convert all entries to ints') | ||
|
||
|
||
def validate_color(s): | ||
|
@@ -263,10 +269,10 @@ def validate_colorlist(s): | |
def validate_stringlist(s): | ||
'return a list' | ||
if isinstance(s, six.string_types): | ||
return [v.strip() for v in s.split(',')] | ||
return [six.text_type(v.strip()) for v in s.split(',') if v.strip()] | ||
else: | ||
assert type(s) in [list, tuple] | ||
return [six.text_type(v) for v in s] | ||
return [six.text_type(v) for v in s if v] | ||
|
||
|
||
validate_orientation = ValidateInStrings( | ||
|
@@ -517,7 +523,7 @@ def __call__(self, s): | |
|
||
|
||
## font props | ||
'font.family': ['sans-serif', validate_stringlist], # used by text object | ||
'font.family': [['sans-serif'], validate_stringlist], # used by text object | ||
'font.style': ['normal', six.text_type], | ||
'font.variant': ['normal', six.text_type], | ||
'font.stretch': ['normal', six.text_type], | ||
|
@@ -776,14 +782,14 @@ def __call__(self, s): | |
'keymap.home': [['h', 'r', 'home'], validate_stringlist], | ||
'keymap.back': [['left', 'c', 'backspace'], validate_stringlist], | ||
'keymap.forward': [['right', 'v'], validate_stringlist], | ||
'keymap.pan': ['p', validate_stringlist], | ||
'keymap.zoom': ['o', validate_stringlist], | ||
'keymap.save': [('s', 'ctrl+s'), validate_stringlist], | ||
'keymap.quit': [('ctrl+w', 'cmd+w'), validate_stringlist], | ||
'keymap.grid': ['g', validate_stringlist], | ||
'keymap.yscale': ['l', validate_stringlist], | ||
'keymap.pan': [['p'], validate_stringlist], | ||
'keymap.zoom': [['o'], validate_stringlist], | ||
'keymap.save': [['s', 'ctrl+s'], validate_stringlist], | ||
'keymap.quit': [['ctrl+w', 'cmd+w'], validate_stringlist], | ||
'keymap.grid': [['g'], validate_stringlist], | ||
'keymap.yscale': [['l'], validate_stringlist], | ||
'keymap.xscale': [['k', 'L'], validate_stringlist], | ||
'keymap.all_axes': ['a', validate_stringlist], | ||
'keymap.all_axes': [['a'], validate_stringlist], | ||
|
||
# sample data | ||
'examples.directory': ['', six.text_type], | ||
|
@@ -797,21 +803,21 @@ def __call__(self, s): | |
# Path to FFMPEG binary. If just binary name, subprocess uses $PATH. | ||
'animation.ffmpeg_path': ['ffmpeg', six.text_type], | ||
|
||
## Additional arguments for ffmpeg movie writer (using pipes) | ||
'animation.ffmpeg_args': ['', validate_stringlist], | ||
# Additional arguments for ffmpeg movie writer (using pipes) | ||
'animation.ffmpeg_args': [[], validate_stringlist], | ||
# Path to AVConv binary. If just binary name, subprocess uses $PATH. | ||
'animation.avconv_path': ['avconv', six.text_type], | ||
# Additional arguments for avconv movie writer (using pipes) | ||
'animation.avconv_args': ['', validate_stringlist], | ||
'animation.avconv_args': [[], validate_stringlist], | ||
# Path to MENCODER binary. If just binary name, subprocess uses $PATH. | ||
'animation.mencoder_path': ['mencoder', six.text_type], | ||
# Additional arguments for mencoder movie writer (using pipes) | ||
'animation.mencoder_args': ['', validate_stringlist], | ||
'animation.mencoder_args': [[], validate_stringlist], | ||
# Path to convert binary. If just binary name, subprocess uses $PATH | ||
'animation.convert_path': ['convert', six.text_type], | ||
# Additional arguments for mencoder movie writer (using pipes) | ||
|
||
'animation.convert_args': ['', validate_stringlist]} | ||
'animation.convert_args': [[], validate_stringlist]} | ||
|
||
|
||
if __name__ == '__main__': | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the comment is necessary (at all), but a test would be very welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment could be shortened to one or two lines, but noting why update needs to be overridden is helpful; it's not obvious.