From 9ea9e63d221e637f96def355710e58deb86bd5b1 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Fri, 4 Sep 2015 16:54:16 +0200 Subject: [PATCH] ENH Better error message when providing wrong fontsizes --- lib/matplotlib/rcsetup.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 2699311323ec..e5e79775d1d9 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -136,6 +136,7 @@ def validate_float(s): raise ValueError('Could not convert "%s" to float' % s) validate_floatlist = _listify_validator(validate_float) + def validate_float_or_None(s): """convert s to float, None or raise""" # values directly from the rc file can only be strings, @@ -150,6 +151,7 @@ def validate_float_or_None(s): except ValueError: raise ValueError('Could not convert "%s" to float or None' % s) + def validate_dpi(s): """confirm s is string 'figure' or convert s to float or raise""" if s == 'figure': @@ -160,6 +162,7 @@ def validate_dpi(s): raise ValueError('"%s" is not string "figure" or' ' could not convert "%s" to float' % (s, s)) + def validate_int(s): """convert s to int or raise""" try: @@ -167,6 +170,7 @@ def validate_int(s): except ValueError: raise ValueError('Could not convert "%s" to int' % s) + def validate_int_or_None(s): """if not None, tries to validate as an int""" if s=='None': @@ -178,6 +182,7 @@ def validate_int_or_None(s): except ValueError: raise ValueError('Could not convert "%s" to int' % s) + def validate_fonttype(s): """ confirm that this is a Postscript of PDF font type that we know how to @@ -354,15 +359,19 @@ def validate_aspect(s): def validate_fontsize(s): + fontsizes = ['xx-small', 'x-small', 'small', 'medium', 'large', + 'x-large', 'xx-large', 'smaller', 'larger'] if isinstance(s, six.string_types): s = s.lower() - if s in ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', - 'xx-large', 'smaller', 'larger']: + if s in fontsizes: return s try: return float(s) except ValueError: - raise ValueError('not a valid font size') + raise ValueError("%s is not a valid font size. Valid font sizes " + "are %s." % (s, ", ".join(fontsizes))) + + validate_fontsizelist = _listify_validator(validate_fontsize)