@@ -20,9 +20,11 @@ def some_fig():
20
20
21
21
def test_raises_on_bad_index (some_fig ):
22
22
# Check indexing errors can be detected when path used as key to go.Figure
23
+ raised = False
23
24
try :
24
25
x0 = some_fig ["layout.shapes[2].x0" ]
25
26
except IndexError as e :
27
+ raised = True
26
28
assert (
27
29
e .args [0 ].find (
28
30
"""Bad property path:
@@ -31,15 +33,18 @@ def test_raises_on_bad_index(some_fig):
31
33
)
32
34
>= 0
33
35
)
36
+ assert raised
34
37
35
38
36
39
def test_raises_on_bad_dot_property (some_fig ):
37
40
38
41
# Check . property lookup errors can be detected when path used as key to
39
42
# go.Figure
43
+ raised = False
40
44
try :
41
45
x2000 = some_fig ["layout.shapes[1].x2000" ]
42
46
except ValueError as e :
47
+ raised = True
43
48
assert (
44
49
e .args [0 ].find (
45
50
"""Bad property path:
@@ -48,14 +53,17 @@ def test_raises_on_bad_dot_property(some_fig):
48
53
)
49
54
>= 0
50
55
)
56
+ assert raised
51
57
52
58
53
59
def test_raises_on_bad_ancestor_dot_property (some_fig ):
54
60
55
61
# Check . property lookup errors but not on the last part of the path
62
+ raised = False
56
63
try :
57
64
x2000 = some_fig ["layout.shapa[1].x2000" ]
58
65
except ValueError as e :
66
+ raised = True
59
67
assert (
60
68
e .args [0 ].find (
61
69
"""Bad property path:
@@ -64,16 +72,19 @@ def test_raises_on_bad_ancestor_dot_property(some_fig):
64
72
)
65
73
>= 0
66
74
)
75
+ assert raised
67
76
68
77
69
78
def test_raises_on_bad_indexed_underscore_property (some_fig ):
70
79
71
80
# finds bad part when using the path as a key to figure and throws the error
72
81
# for the last good property it found in the path
82
+ raised = False
73
83
try :
74
84
# get the error without using a path-like key, we compare with this error
75
85
some_fig .data [0 ].line ["colr" ] = "blue"
76
86
except ValueError as e_correct :
87
+ raised = True
77
88
# remove "Bad property path:
78
89
e_correct_substr = error_substr (
79
90
e_correct .args [0 ],
@@ -85,9 +96,13 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
85
96
# if the string starts with "Bad property path:" then this test cannot work
86
97
# this way.
87
98
assert len (e_correct_substr ) > 0
99
+ assert raised
100
+
101
+ raised = False
88
102
try :
89
103
some_fig ["data[0].line_colr" ] = "blue"
90
104
except ValueError as e :
105
+ raised = True
91
106
e_substr = error_substr (
92
107
e .args [0 ],
93
108
"""
@@ -106,24 +121,31 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
106
121
)
107
122
and (e_substr == e_correct_substr )
108
123
)
124
+ assert raised
109
125
126
+ raised = False
110
127
try :
111
128
# get the error without using a path-like key
112
129
some_fig .add_trace (go .Scatter (x = [1 , 2 ], y = [3 , 4 ], line = dict (colr = "blue" )))
113
130
except ValueError as e_correct :
131
+ raised = True
114
132
e_correct_substr = error_substr (
115
133
e_correct .args [0 ],
116
134
"""
117
135
Bad property path:
118
136
colr
119
137
^""" ,
120
138
)
139
+ assert raised
140
+
141
+ raised = False
121
142
# finds bad part when using the path as a keyword argument to a subclass of
122
143
# BasePlotlyType and throws the error for the last good property found in
123
144
# the path
124
145
try :
125
146
some_fig .add_trace (go .Scatter (x = [1 , 2 ], y = [3 , 4 ], line_colr = "blue" ))
126
147
except ValueError as e :
148
+ raised = True
127
149
e_substr = error_substr (
128
150
e .args [0 ],
129
151
"""
@@ -142,24 +164,30 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
142
164
)
143
165
and (e_substr == e_correct_substr )
144
166
)
167
+ assert raised
145
168
169
+ raised = False
146
170
# finds bad part when using the path as a keyword argument to a subclass of
147
171
# BaseFigure and throws the error for the last good property found in
148
172
# the path
149
173
try :
150
174
fig2 = go .Figure (layout = dict (title = dict (txt = "two" )))
151
175
except ValueError as e_correct :
176
+ raised = True
152
177
e_correct_substr = error_substr (
153
178
e_correct .args [0 ],
154
179
"""
155
180
Bad property path:
156
181
txt
157
182
^""" ,
158
183
)
184
+ assert raised
159
185
186
+ raised = False
160
187
try :
161
188
fig2 = go .Figure (layout_title_txt = "two" )
162
189
except TypeError as e :
190
+ raised = True
163
191
# when the Figure constructor sees the same ValueError above, a
164
192
# TypeError is raised and adds an error message in front of the same
165
193
# ValueError thrown above
@@ -187,22 +215,29 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
187
215
)
188
216
and (e_substr == e_correct_substr )
189
217
)
218
+ assert raised
190
219
220
+ raised = False
191
221
# this is like the above test for subclasses of BasePlotlyType but makes sure it
192
222
# works when the bad part is not the last part in the path
193
223
try :
194
224
some_fig .update_layout (geo = dict (ltaxis = dict (showgrid = True )))
195
225
except ValueError as e_correct :
226
+ raised = True
196
227
e_correct_substr = error_substr (
197
228
e_correct .args [0 ],
198
229
"""
199
230
Bad property path:
200
231
ltaxis
201
232
^""" ,
202
233
)
234
+ assert raised
235
+
236
+ raised = False
203
237
try :
204
238
some_fig .update_layout (geo_ltaxis_showgrid = True )
205
239
except ValueError as e :
240
+ raised = True
206
241
e_substr = error_substr (
207
242
e .args [0 ],
208
243
"""
@@ -221,3 +256,4 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
221
256
)
222
257
and (e_substr == e_correct_substr )
223
258
)
259
+ assert raised
0 commit comments