Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make validate_linestyle private and case insensitive (+ adapt relevan…
…t test)
  • Loading branch information
afvincent committed Feb 13, 2017
commit 7bd9bfe54cf2568ac0df2013e7f322454227abda
41 changes: 22 additions & 19 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,18 +890,21 @@ def validate_animation_writer_path(p):

# A validator dedicated to the named line styles, based on the items in
# ls_mapper, and a list of possible strings read from Line2D.set_linestyle
validate_named_linestyle = ValidateInStrings('linestyle',
list(six.iterkeys(ls_mapper)) +
list(six.itervalues(ls_mapper)) +
['None', 'none', ' ', ''],
ignorecase=False)

# A validator for all possible line styles, the named ones *and*
# the on-off ink sequences.
def validate_linestyle(ls):
_validate_named_linestyle = ValidateInStrings('linestyle',
list(six.iterkeys(ls_mapper)) +
list(six.itervalues(ls_mapper)) +
['None', 'none', ' ', ''],
ignorecase=True)


def _validate_linestyle(ls):
"""
A validator for all possible line styles, the named ones *and*
the on-off ink sequences.
"""
# Named line style, like u'--' or u'solid'
if isinstance(ls, six.text_type):
return validate_named_linestyle(ls)
return _validate_named_linestyle(ls)

# On-off ink (in points) sequence *of even length*.
# Offset is set to None.
Expand Down Expand Up @@ -942,7 +945,7 @@ def validate_linestyle(ls):

# line props
'lines.linewidth': [1.5, validate_float], # line width in points
'lines.linestyle': ['-', validate_linestyle], # solid line
'lines.linestyle': ['-', _validate_linestyle], # solid line
'lines.color': ['C0', validate_color], # first color in color cycle
'lines.marker': ['None', six.text_type], # marker name
'lines.markeredgewidth': [1.0, validate_float],
Expand Down Expand Up @@ -991,31 +994,31 @@ def validate_linestyle(ls):
'boxplot.flierprops.markerfacecolor': ['none', validate_color_or_auto],
'boxplot.flierprops.markeredgecolor': ['k', validate_color],
'boxplot.flierprops.markersize': [6, validate_float],
'boxplot.flierprops.linestyle': ['none', validate_linestyle],
'boxplot.flierprops.linestyle': ['none', _validate_linestyle],
'boxplot.flierprops.linewidth': [1.0, validate_float],

'boxplot.boxprops.color': ['k', validate_color],
'boxplot.boxprops.linewidth': [1.0, validate_float],
'boxplot.boxprops.linestyle': ['-', validate_linestyle],
'boxplot.boxprops.linestyle': ['-', _validate_linestyle],

'boxplot.whiskerprops.color': ['k', validate_color],
'boxplot.whiskerprops.linewidth': [1.0, validate_float],
'boxplot.whiskerprops.linestyle': ['-', validate_linestyle],
'boxplot.whiskerprops.linestyle': ['-', _validate_linestyle],

'boxplot.capprops.color': ['k', validate_color],
'boxplot.capprops.linewidth': [1.0, validate_float],
'boxplot.capprops.linestyle': ['-', validate_linestyle],
'boxplot.capprops.linestyle': ['-', _validate_linestyle],

'boxplot.medianprops.color': ['C1', validate_color],
'boxplot.medianprops.linewidth': [1.0, validate_float],
'boxplot.medianprops.linestyle': ['-', validate_linestyle],
'boxplot.medianprops.linestyle': ['-', _validate_linestyle],

'boxplot.meanprops.color': ['C2', validate_color],
'boxplot.meanprops.marker': ['^', six.text_type],
'boxplot.meanprops.markerfacecolor': ['C2', validate_color],
'boxplot.meanprops.markeredgecolor': ['C2', validate_color],
'boxplot.meanprops.markersize': [6, validate_float],
'boxplot.meanprops.linestyle': ['--', validate_linestyle],
'boxplot.meanprops.linestyle': ['--', _validate_linestyle],
'boxplot.meanprops.linewidth': [1.0, validate_float],

## font props
Expand Down Expand Up @@ -1081,7 +1084,7 @@ def validate_linestyle(ls):
'image.composite_image': [True, validate_bool],

# contour props
'contour.negative_linestyle': ['dashed', validate_linestyle],
'contour.negative_linestyle': ['dashed', _validate_linestyle],
'contour.corner_mask': [True, validate_corner_mask],

# errorbar props
Expand Down Expand Up @@ -1244,7 +1247,7 @@ def validate_linestyle(ls):
'ytick.direction': ['out', six.text_type], # direction of yticks

'grid.color': ['#b0b0b0', validate_color], # grid color
'grid.linestyle': ['-', validate_linestyle], # solid
'grid.linestyle': ['-', _validate_linestyle], # solid
'grid.linewidth': [0.8, validate_float], # in points
'grid.alpha': [1.0, validate_float],

Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
validate_cycler,
validate_hatch,
validate_hist_bins,
validate_linestyle)
_validate_linestyle)


mpl.rc('text', usetex=False)
Expand Down Expand Up @@ -335,19 +335,19 @@ def generate_validator_testcases(valid):
'fail': (('aardvark', ValueError),
)
},
{'validator': validate_linestyle,
{'validator': _validate_linestyle, # NB: case-insensitive
'success': (('-', '-'), ('solid', 'solid'),
('--', '--'), ('dashed', 'dashed'),
('-.', '-.'), ('dashdot', 'dashdot'),
(':', ':'), ('dotted', 'dotted'),
('', ''), (' ', ' '),
('None', 'None'), ('none', 'none'),
('None', 'none'), ('none', 'none'),
('DoTtEd', 'dotted'),
(['1.23', '4.56'], (None, [1.23, 4.56])),
([1.23, 456], (None, [1.23, 456.0])),
([1, 2, 3, 4], (None, [1.0, 2.0, 3.0, 4.0])),
),
'fail': (('aardvark', ValueError), # not a valid string
('DoTtEd', ValueError), # validation is case-sensitive
((None, [1, 2]), ValueError), # (offset, dashes) is not OK
((0, [1, 2]), ValueError), # idem
((-1, [1, 2]), ValueError), # idem
Expand Down