File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -977,7 +977,12 @@ def set_linestyle(self, linestyle):
977
977
break
978
978
979
979
if linestyle not in self ._lineStyles :
980
- linestyle = ls_mapper_r .get (linestyle , linestyle )
980
+ try :
981
+ linestyle = ls_mapper_r [linestyle ]
982
+ except KeyError :
983
+ raise ValueError ("You passed in an invalid linestyle, see "
984
+ "docs of Line2D.set_linestyle for "
985
+ "valid values" )
981
986
if linestyle in [' ' , '' ]:
982
987
linestyle = 'None'
983
988
self ._linestyle = linestyle
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
+ from nose .tools import assert_true , assert_raises
10
10
from timeit import repeat
11
11
import numpy as np
12
12
import matplotlib as mpl
13
13
import matplotlib .pyplot as plt
14
14
from matplotlib .testing .decorators import cleanup , image_comparison
15
+ import sys
15
16
16
17
17
18
@cleanup
@@ -104,6 +105,17 @@ def test_linestyle_variants():
104
105
assert True
105
106
106
107
108
+ @cleanup
109
+ def test_valid_linestyles ():
110
+ if sys .version_info [:2 ] < (2 , 7 ):
111
+ raise nose .SkipTest ("assert_raises as context manager "
112
+ "not supported with Python < 2.7" )
113
+
114
+ line = mpl .lines .Line2D ([], [])
115
+ with assert_raises (ValueError ):
116
+ line .set_linestyle ('aardvark' )
117
+
118
+
107
119
@image_comparison (baseline_images = ['line_collection_dashes' ], remove_text = True )
108
120
def test_set_line_coll_dash_image ():
109
121
fig = plt .figure ()
You can’t perform that action at this time.
0 commit comments