Skip to content

Commit a1ef556

Browse files
Merge pull request #3426 from tirkarthi/fix-assert
Use assertRaisesRegex instead of assertRaisesRegexp for Python 3.11 compatibility
2 parents 43db0c4 + fe66805 commit a1ef556

File tree

10 files changed

+99
-105
lines changed

10 files changed

+99
-105
lines changed

Diff for: packages/python/chart-studio/chart_studio/tests/test_optional/test_grid/test_grid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ def test_duplicate_columns(self):
2727
'the column "{}" and try again.'.format("col_1")
2828
)
2929

30-
with self.assertRaisesRegexp(InputError, expected_message):
30+
with self.assertRaisesRegex(InputError, expected_message):
3131
Grid(df)

Diff for: packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_dashboard/test_dashboard.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_invalid_path(self):
2929
"the strings 'first' and 'second'."
3030
)
3131

32-
self.assertRaisesRegexp(PlotlyError, message, dash._insert, my_box, "third")
32+
self.assertRaisesRegex(PlotlyError, message, dash._insert, my_box, "third")
3333

3434
def test_box_id_none(self):
3535

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

52-
self.assertRaisesRegexp(
53-
PlotlyError, message, dash.insert, my_box, "above", None
54-
)
52+
self.assertRaisesRegex(PlotlyError, message, dash.insert, my_box, "above", None)
5553

5654
def test_id_not_valid(self):
5755
my_box = {
@@ -71,12 +69,12 @@ def test_id_not_valid(self):
7169
dash.insert(my_box, "above", 1)
7270

7371
# insert box
74-
self.assertRaisesRegexp(PlotlyError, message, dash.insert, my_box, "above", 0)
72+
self.assertRaisesRegex(PlotlyError, message, dash.insert, my_box, "above", 0)
7573
# get box by id
76-
self.assertRaisesRegexp(PlotlyError, message, dash.get_box, 0)
74+
self.assertRaisesRegex(PlotlyError, message, dash.get_box, 0)
7775

7876
# remove box
79-
self.assertRaisesRegexp(PlotlyError, message, dash.remove, 0)
77+
self.assertRaisesRegex(PlotlyError, message, dash.remove, 0)
8078

8179
def test_invalid_side(self):
8280
my_box = {
@@ -96,7 +94,7 @@ def test_invalid_side(self):
9694
dash = dashboard.Dashboard()
9795
dash.insert(my_box, "above", 0)
9896

99-
self.assertRaisesRegexp(
97+
self.assertRaisesRegex(
10098
PlotlyError, message, dash.insert, my_box, "somewhere", 1
10199
)
102100

Diff for: packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_credentials.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_sign_in_cannot_validate(self):
7878
self.users_current_mock.side_effect = exceptions.PlotlyRequestError(
7979
"msg", 400, "foobar"
8080
)
81-
with self.assertRaisesRegexp(
81+
with self.assertRaisesRegex(
8282
_plotly_utils.exceptions.PlotlyError, "Sign in failed"
8383
):
8484
py.sign_in("foo", "bar")

Diff for: packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ def test_plot_sharing_invalid_argument(self):
7373

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

76-
with self.assertRaisesRegexp(
77-
PlotlyError, "The 'sharing' argument only accepts"
78-
):
76+
with self.assertRaisesRegex(PlotlyError, "The 'sharing' argument only accepts"):
7977
py.plot(self.simple_figure, **kwargs)
8078

8179
def test_plot_world_readable_sharing_conflict_1(self):
@@ -88,7 +86,7 @@ def test_plot_world_readable_sharing_conflict_1(self):
8886
"sharing": "public",
8987
}
9088

91-
with self.assertRaisesRegexp(
89+
with self.assertRaisesRegex(
9290
PlotlyError, "setting your plot privacy to both public and private."
9391
):
9492
py.plot(self.simple_figure, **kwargs)
@@ -103,7 +101,7 @@ def test_plot_world_readable_sharing_conflict_2(self):
103101
"sharing": "secret",
104102
}
105103

106-
with self.assertRaisesRegexp(
104+
with self.assertRaisesRegex(
107105
PlotlyError, "setting your plot privacy to both public and private."
108106
):
109107
py.plot(self.simple_figure, **kwargs)

Diff for: packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_spectacle_presentation/test_spectacle_presentation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_invalid_style(self):
1919
# one slide
2020
"""
2121

22-
self.assertRaisesRegexp(
22+
self.assertRaisesRegex(
2323
PlotlyError,
2424
chart_studio.presentation_objs.presentation_objs.STYLE_ERROR,
2525
pres.Presentation,
@@ -36,7 +36,7 @@ def test_open_code_block(self):
3636
print x
3737
"""
3838

39-
self.assertRaisesRegexp(
39+
self.assertRaisesRegex(
4040
PlotlyError,
4141
chart_studio.presentation_objs.presentation_objs.CODE_ENV_ERROR,
4242
pres.Presentation,
@@ -52,7 +52,7 @@ def test_invalid_code_language(self):
5252
```
5353
"""
5454

55-
self.assertRaisesRegexp(
55+
self.assertRaisesRegex(
5656
PlotlyError,
5757
chart_studio.presentation_objs.presentation_objs.LANG_ERROR,
5858
pres.Presentation,

Diff for: packages/python/plotly/plotly/tests/test_core/test_colors/test_colors.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_validate_colors(self):
1616
"Plotly scale, an rgb color or a hex color."
1717
)
1818

19-
self.assertRaisesRegexp(
19+
self.assertRaisesRegex(
2020
PlotlyError, pattern, colors.validate_colors, color_string
2121
)
2222

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

30-
self.assertRaisesRegexp(
30+
self.assertRaisesRegex(
3131
PlotlyError, pattern2, colors.validate_colors, color_string2
3232
)
3333

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

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

39-
self.assertRaisesRegexp(
39+
self.assertRaisesRegex(
4040
PlotlyError, pattern3, colors.validate_colors, color_tuple
4141
)
4242

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

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

59-
self.assertRaisesRegexp(
59+
self.assertRaisesRegex(
6060
PlotlyError,
6161
pattern2,
6262
colors.convert_colors_to_same_type,
@@ -72,7 +72,7 @@ def test_convert_dict_colors_to_same_type(self):
7272

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

75-
self.assertRaisesRegexp(
75+
self.assertRaisesRegex(
7676
PlotlyError,
7777
pattern,
7878
colors.convert_dict_colors_to_same_type,
@@ -89,7 +89,7 @@ def test_validate_scale_values(self):
8989
"You must input a list of scale values that has at least " "two values."
9090
)
9191

92-
self.assertRaisesRegexp(
92+
self.assertRaisesRegex(
9393
PlotlyError, pattern, colors.validate_scale_values, scale
9494
)
9595

@@ -101,7 +101,7 @@ def test_validate_scale_values(self):
101101
"1.0 respectively."
102102
)
103103

104-
self.assertRaisesRegexp(
104+
self.assertRaisesRegex(
105105
PlotlyError, pattern, colors.validate_scale_values, scale
106106
)
107107

@@ -113,7 +113,7 @@ def test_validate_scale_values(self):
113113
"increasing sequence of numbers."
114114
)
115115

116-
self.assertRaisesRegexp(
116+
self.assertRaisesRegex(
117117
PlotlyError, pattern, colors.validate_scale_values, scale
118118
)
119119

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

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

127-
self.assertRaisesRegexp(
128-
PlotlyError, pattern, colors.make_colorscale, color_list
129-
)
127+
self.assertRaisesRegex(PlotlyError, pattern, colors.make_colorscale, color_list)
130128

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

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

137-
self.assertRaisesRegexp(
135+
self.assertRaisesRegex(
138136
PlotlyError, pattern2, colors.make_colorscale, color_list2, scale
139137
)
140138

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

147-
self.assertRaisesRegexp(PlotlyError, pattern, colors.get_colorscale, name)
145+
self.assertRaisesRegex(PlotlyError, pattern, colors.get_colorscale, name)
148146

149147
# test for non-existing colorscale
150148
pattern = r"Colorscale \S+ is not a built-in scale."

Diff for: packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_figure.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def test_access_top_level(self):
2828
self.assertEqual(go.Figure().frames, ())
2929

3030
def test_nested_frames(self):
31-
with self.assertRaisesRegexp(ValueError, "frames"):
31+
with self.assertRaisesRegex(ValueError, "frames"):
3232
go.Figure({"frames": [{"frames": []}]})
3333

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

37-
with self.assertRaisesRegexp(ValueError, "frames"):
37+
with self.assertRaisesRegex(ValueError, "frames"):
3838
figure.to_plotly_json()["frames"][0]["frames"] = []
3939
figure.frames[0].frames = []
4040

Diff for: packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_annotations.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_add_annotation_no_grid(self):
8484
self.assertEqual(annot.yref, "paper")
8585

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

9090
def test_add_annotations(self):
@@ -124,7 +124,7 @@ def test_add_annotations(self):
124124
self.assertEqual(annot.yref, "y4")
125125

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

130130
def test_select_annotations_no_grid(self):

0 commit comments

Comments
 (0)