@@ -77,6 +77,14 @@ def test_raises_on_bad_ancestor_dot_property(some_fig):
7777
7878def test_raises_on_bad_indexed_underscore_property (some_fig ):
7979
80+ # The way these tests work is first the error is raised without using
81+ # underscores to get the Exception we expect, then the string showing the
82+ # bad property path is removed (because it will not match the string
83+ # returned when the same error is thrown using underscores).
84+ # Then the error is thrown using underscores and the Exceptions are
85+ # compared, but we adjust the expected bad property error because it will be
86+ # different when underscores are used.
87+
8088 # finds bad part when using the path as a key to figure and throws the error
8189 # for the last good property it found in the path
8290 raised = False
@@ -243,7 +251,7 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
243251 """
244252Bad property path:
245253geo_ltaxis_showgrid
246- ^ """ ,
254+ ^""" ,
247255 )
248256 assert (
249257 (
@@ -257,3 +265,83 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
257265 and (e_substr == e_correct_substr )
258266 )
259267 assert raised
268+
269+
270+ def test_describes_subscripting_error (some_fig ):
271+ # This test works like test_raises_on_bad_indexed_underscore_property but
272+ # removes the error raised because the property does not support
273+ # subscripting.
274+ # Note that, to raise the error, we try to access the value rather than
275+ # assign something to it. We have to do this, because Plotly.py tries to
276+ # access the value to see if it is valid, so the error raised has to do with
277+ # subscripting and not assignment (even though we are trying to assign it a
278+ # value).
279+ raised = False
280+ try :
281+ # some_fig.update_traces(text_yo="hey") but without using underscores
282+ some_fig .data [0 ].text ["yo" ]
283+ except TypeError as e :
284+ raised = True
285+ e_correct_substr = e .args [0 ]
286+ assert raised
287+ raised = False
288+ try :
289+ some_fig .update_traces (text_yo = "hey" )
290+ except TypeError as e :
291+ raised = True
292+ e_substr = error_substr (
293+ e .args [0 ],
294+ """
295+ Property does not support subscripting:
296+ text_yo
297+ ~~~~""" ,
298+ )
299+ assert (
300+ (
301+ e .args [0 ].find (
302+ """
303+ Property does not support subscripting:
304+ text_yo
305+ ~~~~"""
306+ )
307+ >= 0
308+ )
309+ and (e_substr == e_correct_substr )
310+ )
311+ assert raised
312+
313+ # Same as previous test but tests deeper path
314+ raised = False
315+ try :
316+ # go.Figure(go.Scatter()).update_traces(textfont_family_yo="hey") but
317+ # without using underscores
318+ some_fig .data [0 ].textfont .family ["yo" ]
319+ except TypeError as e :
320+ raised = True
321+ e_correct_substr = e .args [0 ]
322+ assert raised
323+ raised = False
324+ try :
325+ go .Figure (go .Scatter ()).update_traces (textfont_family_yo = "hey" )
326+ except TypeError as e :
327+ raised = True
328+ e_substr = error_substr (
329+ e .args [0 ],
330+ """
331+ Property does not support subscripting:
332+ textfont_family_yo
333+ ~~~~~~""" ,
334+ )
335+ assert (
336+ (
337+ e .args [0 ].find (
338+ """
339+ Property does not support subscripting:
340+ textfont_family_yo
341+ ~~~~~~"""
342+ )
343+ >= 0
344+ )
345+ and (e_substr == e_correct_substr )
346+ )
347+ assert raised
0 commit comments