Skip to content

Commit 1816695

Browse files
Use pytest.raises with match argument in set_subplots tests
1 parent b8e23c4 commit 1816695

File tree

1 file changed

+18
-21
lines changed
  • packages/python/plotly/plotly/tests/test_core/test_graph_objs

1 file changed

+18
-21
lines changed

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

+18-21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import plotly.graph_objects as go
44
from plotly.subplots import make_subplots
55
from plotly.tests.utils import TestCaseNoTemplate
6+
import pytest
67

78

89
class FigureTest(TestCaseNoTemplate):
@@ -201,24 +202,20 @@ def test_update_overwrite_data(self):
201202
[{"type": "scatter", "y": [1, 3, 2], "line": {"color": "yellow"}}],
202203
)
203204

204-
def test_set_subplots(self):
205-
# Test that it works the same as make_subplots for a simple call
206-
fig0 = go.Figure()
207-
fig0_sp = make_subplots(2, 2)
208-
fig0.set_subplots(2, 2)
209-
assert fig0.layout == fig0_sp.layout
210-
# Test that it accepts the same arguments as make_subplots
211-
fig1 = go.Figure()
212-
fig1.set_subplots(rows=2, cols=2, horizontal_spacing=0.25, vertical_spacing=0.1)
213-
fig1_sp = make_subplots(
214-
rows=2, cols=2, horizontal_spacing=0.25, vertical_spacing=0.1
215-
)
216-
assert fig1.layout == fig1_sp.layout
217-
# Test that calling on a figure that already has subplots throws an error.
218-
raised = False
219-
try:
220-
fig1.set_subplots(2, 3)
221-
except ValueError as e:
222-
assert e.args[0] == "This figure already has subplots."
223-
raised = True
224-
assert raised
205+
206+
def test_set_subplots():
207+
# Test that it works the same as make_subplots for a simple call
208+
fig0 = go.Figure()
209+
fig0_sp = make_subplots(2, 2)
210+
fig0.set_subplots(2, 2)
211+
assert fig0.layout == fig0_sp.layout
212+
# Test that it accepts the same arguments as make_subplots
213+
fig1 = go.Figure()
214+
fig1.set_subplots(rows=2, cols=2, horizontal_spacing=0.25, vertical_spacing=0.1)
215+
fig1_sp = make_subplots(
216+
rows=2, cols=2, horizontal_spacing=0.25, vertical_spacing=0.1
217+
)
218+
assert fig1.layout == fig1_sp.layout
219+
# Test that calling on a figure that already has subplots throws an error.
220+
with pytest.raises(ValueError, match=r"^This figure already has subplots\.$"):
221+
fig1.set_subplots(2, 3)

0 commit comments

Comments
 (0)