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

Skip to content

Commit 1042544

Browse files
committed
template test passes.
1 parent 3840623 commit 1042544

3 files changed

Lines changed: 88 additions & 80 deletions

File tree

lib/matplotlib/rcsetup.py

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,15 @@ def validate_colorlist(s):
259259
return [validate_color(c) for c in s]
260260

261261

262+
def validate_string(s):
263+
'return a clean string'
264+
assert isinstance(s, basestring)
265+
return s.strip("'").strip()
266+
262267
def validate_stringlist(s):
263268
'return a list'
264269
if type(s) in (str, unicode):
265-
return [v.strip() for v in s.split(',')]
270+
return [validate_string(v) for v in s.split(',')]
266271
else:
267272
assert type(s) in [list, tuple]
268273
return [str(v) for v in s]
@@ -402,11 +407,13 @@ def deprecate_svg_embed_char_paths(value):
402407

403408

404409
def validate_hinting(s):
405-
if s in (True, False):
406-
return s
407-
if s.lower() in ('auto', 'native', 'either', 'none'):
408-
return s.lower()
409-
raise ValueError("hinting should be 'auto', 'native', 'either' or 'none'")
410+
try :
411+
return validate_bool(s)
412+
except ValueError :
413+
if s.lower() in ('auto', 'native', 'either', 'none'):
414+
return s.lower()
415+
else :
416+
raise ValueError("hinting should be 'auto', 'native', 'either' or 'none'")
410417

411418
validate_pgf_texsystem = ValidateInStrings('pgf.texsystem',
412419
['xelatex', 'lualatex', 'pdflatex'])
@@ -495,7 +502,7 @@ def __call__(self, s):
495502
# line props
496503
'lines.linewidth': [1.0, validate_float], # line width in points
497504
'lines.linestyle': ['-', str], # solid line
498-
'lines.color': ['b', validate_color], # blue
505+
'lines.color': ['blue', validate_color], # b=blue
499506
'lines.marker': ['None', str], # black
500507
'lines.markeredgewidth': [0.5, validate_float],
501508
'lines.markersize': [6, validate_float], # markersize, in points
@@ -507,17 +514,17 @@ def __call__(self, s):
507514

508515
## patch props
509516
'patch.linewidth': [1.0, validate_float], # line width in points
510-
'patch.edgecolor': ['k', validate_color], # black
511-
'patch.facecolor': ['b', validate_color], # blue
517+
'patch.edgecolor': ['black', validate_color], # k=black
518+
'patch.facecolor': ['blue', validate_color], # b=blue
512519
'patch.antialiased': [True, validate_bool], # antialised (no jaggies)
513520

514521

515522
## font props
516-
'font.family': ['sans-serif', validate_stringlist], # used by text object
517-
'font.style': ['normal', str],
518-
'font.variant': ['normal', str],
519-
'font.stretch': ['normal', str],
520-
'font.weight': ['normal', str],
523+
'font.family': ['sans-serif', validate_string], # used by text object
524+
'font.style': ['normal', validate_string],
525+
'font.variant': ['normal', validate_string],
526+
'font.stretch': ['normal', validate_string],
527+
'font.weight': ['normal', validate_string],
521528
'font.size': [12, validate_float], # Base font size in points
522529
'font.serif': [['Bitstream Vera Serif', 'DejaVu Serif',
523530
'New Century Schoolbook', 'Century Schoolbook L',
@@ -539,7 +546,7 @@ def __call__(self, s):
539546
validate_stringlist],
540547

541548
# text props
542-
'text.color': ['k', validate_color], # black
549+
'text.color': ['black', validate_color], # k=black
543550
'text.usetex': [False, validate_bool],
544551
'text.latex.unicode': [False, validate_bool],
545552
'text.latex.preamble': [[''], validate_stringlist],
@@ -554,7 +561,7 @@ def __call__(self, s):
554561
'mathtext.tt': ['monospace', validate_font_properties],
555562
'mathtext.it': ['serif:italic', validate_font_properties],
556563
'mathtext.bf': ['serif:bold', validate_font_properties],
557-
'mathtext.sf': ['sans\-serif', validate_font_properties],
564+
'mathtext.sf': ['sans', validate_font_properties],
558565
'mathtext.fontset': ['cm', validate_fontset],
559566
'mathtext.default': ['it', validate_mathtext_default],
560567
'mathtext.fallback_to_cm': [True, validate_bool],
@@ -572,16 +579,16 @@ def __call__(self, s):
572579
# axes props
573580
'axes.axisbelow': [False, validate_bool],
574581
'axes.hold': [True, validate_bool],
575-
'axes.facecolor': ['w', validate_color], # background color; white
576-
'axes.edgecolor': ['k', validate_color], # edge color; black
582+
'axes.facecolor': ['white', validate_color], # background color; w=white
583+
'axes.edgecolor': ['black', validate_color], # edge color; k=black
577584
'axes.linewidth': [1.0, validate_float], # edge linewidth
578585
'axes.titlesize': ['large', validate_fontsize], # fontsize of the
579586
# axes title
580587
'axes.grid': [False, validate_bool], # display grid or not
581588
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
582589
# x any y labels
583590
'axes.labelweight': ['normal', str], # fontsize of the x any y labels
584-
'axes.labelcolor': ['k', validate_color], # color of axis label
591+
'axes.labelcolor': ['black', validate_color], # color of axis label
585592
'axes.formatter.limits': [[-7, 7], validate_nseq_int(2)],
586593
# use scientific notation if log10
587594
# of the axis range is smaller than the
@@ -666,7 +673,7 @@ def __call__(self, s):
666673
'ytick.labelsize': ['medium', validate_fontsize],
667674
'ytick.direction': ['in', str], # direction of yticks
668675

669-
'grid.color': ['k', validate_color], # grid color
676+
'grid.color': ['black', validate_color], # grid color
670677
'grid.linestyle': [':', str], # dotted
671678
'grid.linewidth': [0.5, validate_float], # in points
672679
'grid.alpha': [1.0, validate_float],
@@ -677,7 +684,7 @@ def __call__(self, s):
677684
'figure.figsize': [[8.0, 6.0], validate_nseq_float(2)],
678685
'figure.dpi': [80, validate_float], # DPI
679686
'figure.facecolor': ['0.75', validate_color], # facecolor; scalar gray
680-
'figure.edgecolor': ['w', validate_color], # edgecolor; white
687+
'figure.edgecolor': ['white', validate_color], # edgecolor; w=white
681688
'figure.frameon': [True, validate_bool],
682689
'figure.autolayout': [False, validate_bool],
683690
'figure.max_open_warning': [20, validate_int],
@@ -697,8 +704,8 @@ def __call__(self, s):
697704

698705
## Saving figure's properties
699706
'savefig.dpi': [100, validate_float], # DPI
700-
'savefig.facecolor': ['w', validate_color], # facecolor; white
701-
'savefig.edgecolor': ['w', validate_color], # edgecolor; white
707+
'savefig.facecolor': ['white', validate_color], # facecolor; w=white
708+
'savefig.edgecolor': ['white', validate_color], # edgecolor; w=white
702709
'savefig.frameon': [True, validate_bool],
703710
'savefig.orientation': ['portrait', validate_orientation], # edgecolor;
704711
#white
@@ -753,53 +760,52 @@ def __call__(self, s):
753760
'plugins.directory': ['.matplotlib_plugins', str],
754761

755762
'path.simplify': [True, validate_bool],
756-
'path.simplify_threshold': [1.0 / 9.0, ValidateInterval(0.0, 1.0)],
763+
'path.simplify_threshold': [0.1, ValidateInterval(0.0, 1.0)],
757764
'path.snap': [True, validate_bool],
758765
'path.sketch': [None, validate_sketch],
759766
'path.effects': [[], validate_any],
760767
'agg.path.chunksize': [0, validate_int], # 0 to disable chunking;
761768

762769
# key-mappings (multi-character mappings should be a list/tuple)
763-
'keymap.fullscreen': [('f', 'ctrl+f'), validate_stringlist],
770+
'keymap.fullscreen': [['f', 'ctrl+f'], validate_stringlist],
764771
'keymap.home': [['h', 'r', 'home'], validate_stringlist],
765772
'keymap.back': [['left', 'c', 'backspace'], validate_stringlist],
766773
'keymap.forward': [['right', 'v'], validate_stringlist],
767-
'keymap.pan': ['p', validate_stringlist],
768-
'keymap.zoom': ['o', validate_stringlist],
769-
'keymap.save': [('s', 'ctrl+s'), validate_stringlist],
770-
'keymap.quit': [('ctrl+w', 'cmd+w'), validate_stringlist],
771-
'keymap.grid': ['g', validate_stringlist],
772-
'keymap.yscale': ['l', validate_stringlist],
774+
'keymap.pan': [['p'], validate_stringlist],
775+
'keymap.zoom': [['o'], validate_stringlist],
776+
'keymap.save': [['s', 'ctrl+s'], validate_stringlist],
777+
'keymap.quit': [['ctrl+w', 'cmd+w'], validate_stringlist],
778+
'keymap.grid': [['g'], validate_stringlist],
779+
'keymap.yscale': [['l'], validate_stringlist],
773780
'keymap.xscale': [['k', 'L'], validate_stringlist],
774-
'keymap.all_axes': ['a', validate_stringlist],
781+
'keymap.all_axes': [['a'], validate_stringlist],
775782

776783
# sample data
777-
'examples.directory': ['', str],
784+
'examples.directory': ['', validate_string],
778785

779786
# Animation settings
780787
'animation.writer': ['ffmpeg', validate_movie_writer],
781-
'animation.codec': ['mpeg4', str],
788+
'animation.codec': ['mpeg4', validate_string],
782789
'animation.bitrate': [-1, validate_int],
783790
# Controls image format when frames are written to disk
784791
'animation.frame_format': ['png', validate_movie_frame_fmt],
785792
# Path to FFMPEG binary. If just binary name, subprocess uses $PATH.
786-
'animation.ffmpeg_path': ['ffmpeg', str],
793+
'animation.ffmpeg_path': ['ffmpeg', validate_string],
787794

788795
## Additional arguments for ffmpeg movie writer (using pipes)
789-
'animation.ffmpeg_args': ['', validate_stringlist],
796+
'animation.ffmpeg_args': [[''], validate_stringlist],
790797
# Path to AVConv binary. If just binary name, subprocess uses $PATH.
791-
'animation.avconv_path': ['avconv', str],
798+
'animation.avconv_path': ['avconv', validate_string],
792799
# Additional arguments for avconv movie writer (using pipes)
793-
'animation.avconv_args': ['', validate_stringlist],
800+
'animation.avconv_args': [[''], validate_stringlist],
794801
# Path to MENCODER binary. If just binary name, subprocess uses $PATH.
795-
'animation.mencoder_path': ['mencoder', str],
802+
'animation.mencoder_path': ['mencoder', validate_string],
796803
# Additional arguments for mencoder movie writer (using pipes)
797-
'animation.mencoder_args': ['', validate_stringlist],
804+
'animation.mencoder_args': [[''], validate_stringlist],
798805
# Path to convert binary. If just binary name, subprocess uses $PATH
799-
'animation.convert_path': ['convert', str],
806+
'animation.convert_path': ['convert', validate_string],
800807
# Additional arguments for mencoder movie writer (using pipes)
801-
802-
'animation.convert_args': ['', validate_stringlist]}
808+
'animation.convert_args': [[''], validate_stringlist]}
803809

804810

805811
if __name__ == '__main__':

lib/matplotlib/tests/test_rcsetup.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
from matplotlib.tests import assert_str_equal
55

66
templaterc = os.path.join(os.path.dirname(__file__), 'test_rcsetup.rc')
7-
7+
deprecated = ['svg.embed_char_paths', 'savefig.extension']
88

99
def test_defaults():
1010
# the default values should be successfully set by this class
11-
deprecated = ['svg.embed_char_paths', 'savefig.extension']
1211
with mpl.rc_context(rc=mpl.rcsetup.defaultParams):
1312
for k, v in mpl.rcsetup.defaultParams.iteritems():
1413
if k not in deprecated:
@@ -17,16 +16,20 @@ def test_defaults():
1716

1817
def test_template():
1918
# the current matplotlibrc.template should validate successfully
20-
mpl.rc_file(templaterc)
2119
with mpl.rc_context(fname=templaterc):
2220
for k, v in mpl.rcsetup.defaultParams.iteritems():
23-
if mpl.rcParams[k] != v[0]:
24-
print k
25-
print v[0]
26-
print mpl.rcParams[k]
27-
print "---------------"
28-
assert mpl.rcParams[k] == v[0]
29-
21+
if k not in deprecated:
22+
if mpl.rcParams[k] != v[0]:
23+
print k
24+
print "Expected : ", v[0]
25+
print "Expected type", type(v[0])
26+
print "Actual : ", mpl.rcParams[k]
27+
print "Actual type : ", type(mpl.rcParams[k])
28+
print "---------------"
29+
if isinstance(v[0], basestring):
30+
assert mpl.rcParams[k] in [v[0], v[0].lower()]
31+
else :
32+
assert mpl.rcParams[k] == v[0]
3033

3134
def test_unicode():
3235
# unicode formatted valid strings should validate.

lib/matplotlib/tests/test_rcsetup.rc

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ lines.color : blue # has no affect on plot(); see axes.color_cycle
7474
lines.marker : None # the default marker
7575
lines.markeredgewidth : 0.5 # the line width around the marker symbol
7676
lines.markersize : 6 # markersize, in points
77-
lines.dash_joinstyle : miter # miter|round|bevel
77+
lines.dash_joinstyle : round # miter|round|bevel
7878
lines.dash_capstyle : butt # butt|round|projecting
79-
lines.solid_joinstyle : miter # miter|round|bevel
79+
lines.solid_joinstyle : round # miter|round|bevel
8080
lines.solid_capstyle : projecting # butt|round|projecting
8181
lines.antialiased : True # render lines in antialised (no jaggies)
8282

@@ -129,19 +129,19 @@ patch.antialiased : True # render patches in antialised (no jaggies)
129129
font.family : sans-serif
130130
font.style : normal
131131
font.variant : normal
132-
font.weight : medium
132+
font.weight : normal
133133
font.stretch : normal
134134
# note that font.size controls default text sizes. To configure
135135
# special text sizes tick labels, axes, labels, title, etc, see the rc
136136
# settings for axes and ticks. Special text sizes can be defined
137137
# relative to font.size, using the following values: xx-small, x-small,
138138
# small, medium, large, x-large, xx-large, larger, or smaller
139139
font.size : 12.0
140-
font.serif : Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
141-
font.sans-serif : Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
140+
font.serif : Bitstream Vera Serif, DejaVu Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
141+
font.sans-serif : Bitstream Vera Sans, DejaVu Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
142142
font.cursive : Apple Chancery, Textile, Zapf Chancery, Sand, cursive
143143
font.fantasy : Comic Sans MS, Chicago, Charcoal, Impact, Western, fantasy
144-
font.monospace : Bitstream Vera Sans Mono, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace
144+
font.monospace : Bitstream Vera Sans Mono, DejaVu Sans Mono, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace
145145

146146
### TEXT
147147
# text properties used by text.Text. See
@@ -181,7 +181,7 @@ text.dvipnghack : None # some versions of dvipng don't handle alpha
181181
# correction off. None will try and
182182
# guess based on your dvipng version
183183

184-
text.hinting : auto # May be one of the following:
184+
text.hinting : True # May be one of the following:
185185
# 'none': Perform no hinting
186186
# 'auto': Use freetype's autohinter
187187
# 'native': Use the hinting information in the
@@ -292,7 +292,7 @@ legend.fancybox : False # if True, use a rounded box for the
292292
legend.isaxes : True
293293
legend.numpoints : 2 # the number of points in the legend line
294294
legend.fontsize : large
295-
legend.borderpad : 0.5 # border whitespace in fontsize units
295+
legend.borderpad : 0.4 # border whitespace in fontsize units
296296
legend.markerscale : 1.0 # the relative size of legend markers vs. original
297297
# the following dimensions are in axes coords
298298
legend.labelspacing : 0.5 # the vertical space between the legend entries in fraction of fontsize
@@ -351,7 +351,7 @@ agg.path.chunksize : 0 # 0 to disable; values in the range
351351
path.simplify : True # When True, simplify paths by removing "invisible"
352352
# points to reduce file size and increase rendering
353353
# speed
354-
path.simplify_threshold : 0.1 # The threshold of similarity below which
354+
path.simplify_threshold : 0.1 # The threshold of similarity below which
355355
# vertices will be removed in the simplification
356356
# process
357357
path.snap : True # When True, rectilinear axis-aligned paths will be snapped to
@@ -432,35 +432,34 @@ verbose.fileo : sys.stdout # a log filename, sys.stdout or sys.stderr
432432
# Customize these settings according to your needs.
433433
# Leave the field(s) empty if you don't need a key-map. (i.e., fullscreen : '')
434434

435-
keymap.fullscreen : f # toggling
435+
keymap.fullscreen : f, ctrl+f # toggling
436436
keymap.home : h, r, home # home or reset mnemonic
437437
keymap.back : left, c, backspace # forward / backward keys to enable
438438
keymap.forward : right, v # left handed quick navigation
439439
keymap.pan : p # pan mnemonic
440440
keymap.zoom : o # zoom mnemonic
441-
keymap.save : s # saving current figure
441+
keymap.save : s, ctrl+s # saving current figure
442442
keymap.quit : ctrl+w, cmd+w # close the current figure
443443
keymap.grid : g # switching on/off a grid in current axes
444444
keymap.yscale : l # toggle scaling of y-axes ('log'/'linear')
445-
keymap.xscale : L, k # toggle scaling of x-axes ('log'/'linear')
445+
keymap.xscale : k, L # toggle scaling of x-axes ('log'/'linear')
446446
keymap.all_axes : a # enable all axes
447447

448448
# Control location of examples data files
449449
examples.directory : '' # directory to look in for custom installation
450450

451451
###ANIMATION settings
452-
animation.writer : ffmpeg # MovieWriter 'backend' to use
453-
animation.codec : mp4 # Codec to use for writing movie
454-
animation.bitrate: -1 # Controls size/quality tradeoff for movie.
455-
# -1 implies let utility auto-determine
456-
animation.frame_format: png # Controls frame format used by temp files
457-
animation.ffmpeg_path: 'ffmpeg' # Path to ffmpeg binary. Without full path
458-
# $PATH is searched
459-
animation.ffmpeg_args: '' # Additional arguments to pass to ffmpeg
460-
animation.avconv_path: 'avconv' # Path to avconv binary. Without full path
461-
# $PATH is searched
462-
animation.avconv_args: '' # Additional arguments to pass to avconv
463-
animation.mencoder_path: 'mencoder'
464-
# Path to mencoder binary. Without full path
465-
# $PATH is searched
466-
animation.mencoder_args: '' # Additional arguments to pass to mencoder
452+
animation.writer : ffmpeg # MovieWriter 'backend' to use
453+
animation.codec : mpeg4 # Codec to use for writing movie
454+
animation.bitrate: -1 # Controls size/quality tradeoff for movie.
455+
# -1 implies let utility auto-determine
456+
animation.frame_format: png # Controls frame format used by temp files
457+
animation.ffmpeg_path: 'ffmpeg' # Path to ffmpeg binary. Without full path
458+
# $PATH is searched
459+
animation.ffmpeg_args: '' # Additional arguments to pass to ffmpeg
460+
animation.avconv_path: 'avconv' # Path to avconv binary. Without full path
461+
# $PATH is searched
462+
animation.avconv_args: '' # Additional arguments to pass to avconv
463+
animation.mencoder_path: 'mencoder' # Path to mencoder binary. Without full path
464+
# $PATH is searched
465+
animation.mencoder_args: '' # Additional arguments to pass to mencoder

0 commit comments

Comments
 (0)