File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -971,10 +971,18 @@ def set_linestyle(self, linestyle):
971
971
linestyle = '-'
972
972
break
973
973
974
- if linestyle not in self ._lineStyles :
975
- linestyle = ls_mapper_r .get (linestyle , linestyle )
976
- if linestyle in [' ' , '' ]:
974
+ if linestyle in [' ' , '' , 'none' ]:
977
975
linestyle = 'None'
976
+
977
+ if linestyle not in self ._lineStyles :
978
+ try :
979
+ linestyle = ls_mapper_r [linestyle ]
980
+ except KeyError :
981
+ raise ValueError (("You passed in an invalid linestyle, "
982
+ "`{}`. See "
983
+ "docs of Line2D.set_linestyle for "
984
+ "valid values." ).format (linestyle ))
985
+
978
986
self ._linestyle = linestyle
979
987
980
988
@docstring .dedent_interpd
Original file line number Diff line number Diff line change 6
6
7
7
import six
8
8
9
- from nose .tools import assert_true
9
+ import nose
10
+ from nose .tools import assert_true , assert_raises
10
11
from timeit import repeat
11
12
import numpy as np
12
13
import matplotlib as mpl
13
14
import matplotlib .pyplot as plt
14
15
from matplotlib .testing .decorators import cleanup , image_comparison
16
+ import sys
15
17
16
18
17
19
@cleanup
@@ -104,6 +106,17 @@ def test_linestyle_variants():
104
106
assert True
105
107
106
108
109
+ @cleanup
110
+ def test_valid_linestyles ():
111
+ if sys .version_info [:2 ] < (2 , 7 ):
112
+ raise nose .SkipTest ("assert_raises as context manager "
113
+ "not supported with Python < 2.7" )
114
+
115
+ line = mpl .lines .Line2D ([], [])
116
+ with assert_raises (ValueError ):
117
+ line .set_linestyle ('aardvark' )
118
+
119
+
107
120
@image_comparison (baseline_images = ['line_collection_dashes' ], remove_text = True )
108
121
def test_set_line_coll_dash_image ():
109
122
fig = plt .figure ()
@@ -121,5 +134,4 @@ def test_nan_is_sorted():
121
134
122
135
123
136
if __name__ == '__main__' :
124
- import nose
125
137
nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
You can’t perform that action at this time.
0 commit comments