Skip to content

Use assertRaisesRegex instead of assertRaisesRegexp for Python 3.11 compatibility #3426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def test_duplicate_columns(self):
'the column "{}" and try again.'.format("col_1")
)

with self.assertRaisesRegexp(InputError, expected_message):
with self.assertRaisesRegex(InputError, expected_message):
Grid(df)
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_invalid_path(self):
"the strings 'first' and 'second'."
)

self.assertRaisesRegexp(PlotlyError, message, dash._insert, my_box, "third")
self.assertRaisesRegex(PlotlyError, message, dash._insert, my_box, "third")

def test_box_id_none(self):

Expand All @@ -49,9 +49,7 @@ def test_box_id_none(self):
"one box in your dashboard."
)

self.assertRaisesRegexp(
PlotlyError, message, dash.insert, my_box, "above", None
)
self.assertRaisesRegex(PlotlyError, message, dash.insert, my_box, "above", None)

def test_id_not_valid(self):
my_box = {
Expand All @@ -71,12 +69,12 @@ def test_id_not_valid(self):
dash.insert(my_box, "above", 1)

# insert box
self.assertRaisesRegexp(PlotlyError, message, dash.insert, my_box, "above", 0)
self.assertRaisesRegex(PlotlyError, message, dash.insert, my_box, "above", 0)
# get box by id
self.assertRaisesRegexp(PlotlyError, message, dash.get_box, 0)
self.assertRaisesRegex(PlotlyError, message, dash.get_box, 0)

# remove box
self.assertRaisesRegexp(PlotlyError, message, dash.remove, 0)
self.assertRaisesRegex(PlotlyError, message, dash.remove, 0)

def test_invalid_side(self):
my_box = {
Expand All @@ -96,7 +94,7 @@ def test_invalid_side(self):
dash = dashboard.Dashboard()
dash.insert(my_box, "above", 0)

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError, message, dash.insert, my_box, "somewhere", 1
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_sign_in_cannot_validate(self):
self.users_current_mock.side_effect = exceptions.PlotlyRequestError(
"msg", 400, "foobar"
)
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
_plotly_utils.exceptions.PlotlyError, "Sign in failed"
):
py.sign_in("foo", "bar")
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def test_plot_sharing_invalid_argument(self):

kwargs = {"filename": "invalid-sharing-argument", "sharing": "privste"}

with self.assertRaisesRegexp(
PlotlyError, "The 'sharing' argument only accepts"
):
with self.assertRaisesRegex(PlotlyError, "The 'sharing' argument only accepts"):
py.plot(self.simple_figure, **kwargs)

def test_plot_world_readable_sharing_conflict_1(self):
Expand All @@ -87,7 +85,7 @@ def test_plot_world_readable_sharing_conflict_1(self):
"sharing": "public",
}

with self.assertRaisesRegexp(
with self.assertRaisesRegex(
PlotlyError, "setting your plot privacy to both public and private."
):
py.plot(self.simple_figure, **kwargs)
Expand All @@ -102,7 +100,7 @@ def test_plot_world_readable_sharing_conflict_2(self):
"sharing": "secret",
}

with self.assertRaisesRegexp(
with self.assertRaisesRegex(
PlotlyError, "setting your plot privacy to both public and private."
):
py.plot(self.simple_figure, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_invalid_style(self):
# one slide
"""

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError,
chart_studio.presentation_objs.presentation_objs.STYLE_ERROR,
pres.Presentation,
Expand All @@ -36,7 +36,7 @@ def test_open_code_block(self):
print x
"""

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError,
chart_studio.presentation_objs.presentation_objs.CODE_ENV_ERROR,
pres.Presentation,
Expand All @@ -52,7 +52,7 @@ def test_invalid_code_language(self):
```
"""

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError,
chart_studio.presentation_objs.presentation_objs.LANG_ERROR,
pres.Presentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_validate_colors(self):
"Plotly scale, an rgb color or a hex color."
)

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError, pattern, colors.validate_colors, color_string
)

Expand All @@ -27,7 +27,7 @@ def test_validate_colors(self):
"Whoops! The elements in your rgb colors tuples cannot " "exceed 255.0."
)

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError, pattern2, colors.validate_colors, color_string2
)

Expand All @@ -36,7 +36,7 @@ def test_validate_colors(self):

pattern3 = "Whoops! The elements in your colors tuples cannot " "exceed 1.0."

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError, pattern3, colors.validate_colors, color_tuple
)

Expand All @@ -56,7 +56,7 @@ def test_convert_colors_to_same_type(self):

pattern2 = "You must select either rgb or tuple for your colortype " "variable."

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError,
pattern2,
colors.convert_colors_to_same_type,
Expand All @@ -72,7 +72,7 @@ def test_convert_dict_colors_to_same_type(self):

pattern = "You must select either rgb or tuple for your colortype " "variable."

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError,
pattern,
colors.convert_dict_colors_to_same_type,
Expand All @@ -89,7 +89,7 @@ def test_validate_scale_values(self):
"You must input a list of scale values that has at least " "two values."
)

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError, pattern, colors.validate_scale_values, scale
)

Expand All @@ -101,7 +101,7 @@ def test_validate_scale_values(self):
"1.0 respectively."
)

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError, pattern, colors.validate_scale_values, scale
)

Expand All @@ -113,7 +113,7 @@ def test_validate_scale_values(self):
"increasing sequence of numbers."
)

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError, pattern, colors.validate_scale_values, scale
)

Expand All @@ -124,17 +124,15 @@ def test_make_colorscale(self):

pattern = "You must input a list of colors that has at least two colors."

self.assertRaisesRegexp(
PlotlyError, pattern, colors.make_colorscale, color_list
)
self.assertRaisesRegex(PlotlyError, pattern, colors.make_colorscale, color_list)

# test length of colors and scale
color_list2 = [(0, 0, 0), (1, 1, 1)]
scale = [0]

pattern2 = "The length of colors and scale must be the same."

self.assertRaisesRegexp(
self.assertRaisesRegex(
PlotlyError, pattern2, colors.make_colorscale, color_list2, scale
)

Expand All @@ -144,7 +142,7 @@ def test_get_colorscale(self):
pattern = "Name argument have to be a string."
name = colors.sequential.haline

self.assertRaisesRegexp(PlotlyError, pattern, colors.get_colorscale, name)
self.assertRaisesRegex(PlotlyError, pattern, colors.get_colorscale, name)

# test for non-existing colorscale
pattern = r"Colorscale \S+ is not a built-in scale."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def test_access_top_level(self):
self.assertEqual(go.Figure().frames, ())

def test_nested_frames(self):
with self.assertRaisesRegexp(ValueError, "frames"):
with self.assertRaisesRegex(ValueError, "frames"):
go.Figure({"frames": [{"frames": []}]})

figure = go.Figure()
figure.frames = [{}]

with self.assertRaisesRegexp(ValueError, "frames"):
with self.assertRaisesRegex(ValueError, "frames"):
figure.to_plotly_json()["frames"][0]["frames"] = []
figure.frames[0].frames = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_add_annotation_no_grid(self):
self.assertEqual(annot.yref, "paper")

# Not valid to add annotation by row/col
with self.assertRaisesRegexp(Exception, "make_subplots"):
with self.assertRaisesRegex(Exception, "make_subplots"):
fig.add_annotation(text="B", row=1, col=1)

def test_add_annotations(self):
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_add_annotations(self):
self.assertEqual(annot.yref, "y4")

# Try to add to (2, 2), which not a valid
with self.assertRaisesRegexp(ValueError, "of type polar"):
with self.assertRaisesRegex(ValueError, "of type polar"):
self.fig.add_annotation(text="D", row=2, col=2)

def test_select_annotations_no_grid(self):
Expand Down
Loading