Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2209b2d
Better magic underscore errors
nicholas-esterer Oct 19, 2020
afd5b7a
Remove whitespace-only changes
nicholas-esterer Oct 20, 2020
b894b89
Assert that errors are raised
nicholas-esterer Oct 20, 2020
4c659db
Also state when a property doesn't support subscripting
nicholas-esterer Oct 20, 2020
2bf2526
Tests for non-subscriptable property errors
nicholas-esterer Oct 20, 2020
5695969
updated changelog
nicholas-esterer Oct 20, 2020
22b3e03
Improved error message when subscripting types that don't support it
nicholas-esterer Oct 23, 2020
c09c03e
Removed garbage line from test_dict_path_errors.py
nicholas-esterer Oct 23, 2020
f4be2b1
Changed PlotlyKeyError's superclass to KeyError
nicholas-esterer Nov 4, 2020
73051a6
BasePlotlyType._raise_on_invalid_property_error raises PlotlyKeyError
nicholas-esterer Nov 4, 2020
651b712
Cast some errors to PlotlyKeyError
nicholas-esterer Nov 4, 2020
9bb2470
Updated the tests to reflect the new Exception behaviour
nicholas-esterer Nov 4, 2020
bf4cd97
BasePlotlyType.__setitem__ exceptions casted to ValueError
nicholas-esterer Nov 5, 2020
7d42ffe
Merge master's whitespace changes
nicholas-esterer Nov 5, 2020
a18b341
Merge branch 'master' into deep-magic-underscore-error-msg-rebase
nicholas-esterer Nov 5, 2020
4bda7b2
Now subscripting errors triggered on types throwing TypeError
nicholas-esterer Nov 5, 2020
9e1b667
subscripting error tests compatible with Python2
nicholas-esterer Nov 5, 2020
d6aee64
Changed dict path error display to always ^
nicholas-esterer Nov 9, 2020
c6e5b4d
Try taking length of string-like objects
nicholas-esterer Nov 9, 2020
82f9bb1
leading, trailing, multiple underscores detected in dict path strings
nicholas-esterer Nov 9, 2020
70f18ca
Added tests for leading, trailing and embedded extra underscore errors
nicholas-esterer Nov 10, 2020
00851fa
Complain about trailing underscores, find closest key
nicholas-esterer Nov 10, 2020
d2bc400
Updated error messages for trailing underscores and find closest key
nicholas-esterer Nov 10, 2020
20518c1
Key guessing before and after list of valid properties
nicholas-esterer Nov 10, 2020
4066ae2
Test single property key guessing
nicholas-esterer Nov 11, 2020
86f4217
Merge branch 'master' into deep-magic-underscore-error-msg-rebase
nicholas-esterer Nov 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated error messages for trailing underscores and find closest key
  • Loading branch information
nicholas-esterer committed Nov 10, 2020
commit d2bc4006b895b0f31f5838f7c39ad4661474d5a6
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
"""
Bad property path:
data[0].line_colr
^^^^""",
^^^^
Did you mean "color"?""",
)
assert (
(
e.args[0].find(
"""Bad property path:
data[0].line_colr
^^^^"""
^^^^
Did you mean "color"?"""
)
>= 0
)
Expand Down Expand Up @@ -168,7 +170,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
e.args[0].find(
"""Bad property path:
line_colr
^^^^"""
^^^^
Did you mean "color"?"""
)
>= 0
)
Expand All @@ -189,7 +192,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
"""
Bad property path:
txt
^^^""",
^^^
Did you mean "text"?""",
)
assert raised

Expand All @@ -206,7 +210,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
"""
Bad property path:
layout_title_txt
^^^""",
^^^
Did you mean "text"?""",
)
# also remove the invalid Figure property string added by the Figure constructor
e_substr = error_substr(
Expand All @@ -219,7 +224,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
e.args[0].find(
"""Bad property path:
layout_title_txt
^^^"""
^^^
Did you mean "text"?""",
)
>= 0
)
Expand All @@ -239,7 +245,8 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
"""
Bad property path:
ltaxis
^^^^^^""",
^^^^^^
Did you mean "lataxis"?""",
)
assert raised

Expand All @@ -253,14 +260,16 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
"""
Bad property path:
geo_ltaxis_showgrid
^^^^^^""",
^^^^^^
Did you mean "lataxis"?""",
)
assert (
(
e.args[0].find(
"""Bad property path:
geo_ltaxis_showgrid
^^^^^^"""
^^^^^^
Did you mean "lataxis"?"""
)
>= 0
)
Expand Down Expand Up @@ -458,6 +467,10 @@ def check_error_string(call, exception, correct_str, subs):
msg = e.args[0]
for pat, rep in subs:
msg = msg.replace(pat, rep, 1)
print("MSG")
print(msg)
print("CORRECT")
print(correct_str)
assert msg == correct_str
assert raised

Expand All @@ -473,23 +486,38 @@ def _raise_bad_property_path_real():
correct_err_str = form_error_string(
_raise_bad_property_path_form,
ValueError,
[("bogus", "_"), ("bogus", "_hey_yall"), ("^^^^^", "^")],
# change last boxgap to geo because bogus is closest to boxgap but _hey
# closest to geo, but remember that boxgap is in the list of valid keys
# displayed by the error string
[
("bogus", "_hey"),
("bogus", "_hey_yall"),
("^^^^^", "^^^^"),
('Did you mean "boxgap"', 'Did you mean "geo"'),
],
)
check_error_string(_raise_bad_property_path_real, ValueError, correct_err_str, [])


def test_trailing_underscore_errors(some_fig):
# get error string but alter it to form the final expected string
def _raise_bad_property_path_form():
some_fig.update_layout(title_bogus="hi")
some_fig.update_layout(title_text_bogus="hi")

def _raise_bad_property_path_real():
some_fig.update_layout(title_text_="hi")

correct_err_str = form_error_string(
_raise_bad_property_path_form,
ValueError,
[("bogus", "text_"), ("title_bogus", "title_text_")],
[
(
"Property does not support subscripting",
"Property does not support subscripting and path has trailing underscores",
),
("text_bogus", "text_"),
("^^^^", "^^^^^"),
],
)
# no need to replace ^^^^^ because bogus and text_ are same length
check_error_string(_raise_bad_property_path_real, ValueError, correct_err_str, [])
Expand All @@ -498,15 +526,19 @@ def _raise_bad_property_path_real():
def test_embedded_underscore_errors(some_fig):
# get error string but alter it to form the final expected string
def _raise_bad_property_path_form():
some_fig.update_layout(title_bogus_family="hi")
some_fig.update_layout(title_font_bogusey="hi")

def _raise_bad_property_path_real():
some_fig.update_layout(title_font__family="hi")

correct_err_str = form_error_string(
_raise_bad_property_path_form,
ValueError,
[("bogus", "font_"), ("title_bogus_family", "title_font__family")],
[
("bogusey", "_family"),
("bogusey", "_family"),
('Did you mean "size"?', 'Did you mean "family"?'),
],
)
# no need to replace ^^^^^ because bogus and font_ are same length
check_error_string(_raise_bad_property_path_real, ValueError, correct_err_str, [])
Expand All @@ -523,7 +555,12 @@ def _raise_bad_property_path_real():
correct_err_str = form_error_string(
_raise_bad_property_path_form,
ValueError,
[("bogus", "_"), ("bogus", "_"), ("^^^^^", "^")],
[
("bogus", "_"),
("bogus", "_"),
("^^^^^", "^"),
('Did you mean "boxgap"', 'Did you mean "geo"'),
],
)
check_error_string(_raise_bad_property_path_real, ValueError, correct_err_str, [])

Expand All @@ -539,7 +576,12 @@ def _raise_bad_property_path_real():
correct_err_str = form_error_string(
_raise_bad_property_path_form,
ValueError,
[("bogus", "__"), ("bogus", "__"), ("^^^^^", "^^")],
[
("bogus", "__"),
("bogus", "__"),
("^^^^^", "^^"),
('Did you mean "boxgap"', 'Did you mean "geo"'),
],
)
check_error_string(_raise_bad_property_path_real, ValueError, correct_err_str, [])

Expand All @@ -557,7 +599,7 @@ def _raise_bad_property_path_real():
correct_err_str = form_error_string(
_raise_bad_property_path_form,
ValueError,
[("bogus", "_"), ("bogus", "_font"), ("^^^^^", "^")],
[("bogus", "_font"), ("bogus", "_font"), ("^^^^^", "^^^^^")],
)
check_error_string(_raise_bad_property_path_real, ValueError, correct_err_str, [])

Expand All @@ -567,15 +609,22 @@ def test_trailing_underscore_errors_dots_and_subscripts(some_fig):
some_fig.add_annotation(text="hi")

def _raise_bad_property_path_form():
some_fig["layout.annotations[0].font_bogusey"] = "hi"
some_fig["layout.annotations[0].font_family_bogus"] = "hi"

def _raise_bad_property_path_real():
some_fig["layout.annotations[0].font_family_"] = "hi"

correct_err_str = form_error_string(
_raise_bad_property_path_form,
ValueError,
[("bogusey", "family_"), ("bogusey", "family_")],
[
(
"Property does not support subscripting",
"Property does not support subscripting and path has trailing underscores",
),
("family_bogus", "family_"),
("^^^^^^", "^^^^^^^"),
],
)
check_error_string(_raise_bad_property_path_real, ValueError, correct_err_str, [])

Expand All @@ -585,14 +634,18 @@ def test_repeated_underscore_errors_dots_and_subscripts(some_fig):
some_fig.add_annotation(text="hi")

def _raise_bad_property_path_form():
some_fig["layout.annotations[0].bogus_family"] = "hi"
some_fig["layout.annotations[0].font_bogusey"] = "hi"

def _raise_bad_property_path_real():
some_fig["layout.annotations[0].font__family"] = "hi"

correct_err_str = form_error_string(
_raise_bad_property_path_form,
ValueError,
[("bogus", "font_"), ("bogus", "font_")],
[
("bogusey", "_family"),
("bogusey", "_family"),
('Did you mean "size"?', 'Did you mean "family"?'),
],
)
check_error_string(_raise_bad_property_path_real, ValueError, correct_err_str, [])