Skip to content

Commit 9e1b667

Browse files
subscripting error tests compatible with Python2
1 parent 4bda7b2 commit 9e1b667

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

packages/python/plotly/plotly/tests/test_core/test_errors/test_dict_path_errors.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,16 @@ def test_described_subscript_error_on_type_error(some_fig):
375375
some_fig["layout_template_layout_plot_bgcolor"] = 1
376376
except ValueError as e:
377377
raised = True
378-
e_correct_substr = error_substr(
379-
e.args[0],
380-
"""
381-
Invalid value of type 'builtins.int' received for the 'plot_bgcolor' property of layout
382-
Received value: 1
383-
""",
384-
)
378+
# Trim off the beginning of the error string because it is related to
379+
# trying to assign a number to something expecting a string, whereas
380+
# below the error will be due to trying to subscript something that
381+
# doesn't support it. But the list of valid properties should be shown
382+
# for both errors and this is what we extract.
383+
# Trimmed like this because this string is different in Python2 than
384+
# Python3
385+
e_correct_substr = e.args[0]
386+
start_at = e_correct_substr.find(" The 'plot_bgcolor'")
387+
e_correct_substr = e_correct_substr[start_at:]
385388
e_correct_substr += """
386389
387390
Property does not support subscripting:
@@ -399,6 +402,7 @@ def test_described_subscript_error_on_type_error(some_fig):
399402
"""string indices must be integers
400403
401404
Invalid value received for the 'plot_bgcolor' property of layout
405+
402406
""",
403407
)
404408
assert e_substr == e_correct_substr

0 commit comments

Comments
 (0)