|
3 | 3 | import plotly.graph_objects as go
|
4 | 4 | from plotly.subplots import make_subplots
|
5 | 5 | from plotly.tests.utils import TestCaseNoTemplate
|
| 6 | +import pytest |
6 | 7 |
|
7 | 8 |
|
8 | 9 | class FigureTest(TestCaseNoTemplate):
|
@@ -201,24 +202,20 @@ def test_update_overwrite_data(self):
|
201 | 202 | [{"type": "scatter", "y": [1, 3, 2], "line": {"color": "yellow"}}],
|
202 | 203 | )
|
203 | 204 |
|
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