Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Format: reformat the a new unit tests
  • Loading branch information
Erik Paskalev committed Jun 27, 2025
commit f8432ee9ec4d9c9175d2ef5de30c018840ad81cd
12 changes: 7 additions & 5 deletions tests/test_core/test_shapes/test_add_hline_empty_subplots.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import pytest
from plotly.subplots import make_subplots


def test_add_hline_on_empty_subplots_creates_shape_default():
fig = make_subplots(rows=1, cols=1)
fig.add_hline(y=0.25)
shapes = fig.layout.shapes
assert len(shapes) == 1, "Expected one shape for the horizontal line"
shape = shapes[0]
assert shape.type == 'line'
assert shape.type == "line"
assert shape.y0 == 0.25 and shape.y1 == 0.25
# xref and yref should be set
assert getattr(shape, 'xref', None) is not None
assert getattr(shape, 'yref', None) is not None
assert getattr(shape, "xref", None) is not None
assert getattr(shape, "yref", None) is not None


@pytest.mark.parametrize("row, col", [(None, None), (1, 1)])
def test_add_hline_with_explicit_row_col_on_empty_subplots(row, col):
Expand All @@ -22,7 +24,7 @@ def test_add_hline_with_explicit_row_col_on_empty_subplots(row, col):
assert len(shapes) == 1, f"Expected one shape when row={row}, col={col}"
shape = shapes[0]
assert shape.y0 == 0.5 and shape.y1 == 0.5
assert shape.type == 'line'
assert shape.type == "line"
# ensure references default
assert shape.xref is not None
assert shape.yref is not None
assert shape.yref is not None
35 changes: 25 additions & 10 deletions tests/test_regression/test_hline_subplots_bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,30 @@ def _apply_line(fig, orientation):
raise ValueError("orientation must be 'h' or 'v'")


@pytest.mark.parametrize("orientation,kwargs", [
("h", dict(line_coord_key="y0", coord=0.5, span_keys=("x0", "x1"), span_vals=(0, 1))),
("v", dict(line_coord_key="x0", coord=0.3, span_keys=("y0", "y1"), span_vals=(0, 1))),
])
@pytest.mark.parametrize("constructor", [
pytest.param(lambda: go.Figure(), id="plain-figure"),
pytest.param(lambda: make_subplots(rows=1, cols=1), id="make_subplots"),
])

@pytest.mark.parametrize(
"orientation,kwargs",
[
(
"h",
dict(
line_coord_key="y0", coord=0.5, span_keys=("x0", "x1"), span_vals=(0, 1)
),
),
(
"v",
dict(
line_coord_key="x0", coord=0.3, span_keys=("y0", "y1"), span_vals=(0, 1)
),
),
],
)
@pytest.mark.parametrize(
"constructor",
[
pytest.param(lambda: go.Figure(), id="plain-figure"),
pytest.param(lambda: make_subplots(rows=1, cols=1), id="make_subplots"),
],
)
def test_add_line_presence(orientation, kwargs, constructor):
"""Both add_hline and add_vline must create a shape, even on empty subplots."""
fig = constructor()
Expand All @@ -43,4 +58,4 @@ def test_add_line_presence(orientation, kwargs, constructor):
span_key0, span_key1 = kwargs["span_keys"]
expected0, expected1 = kwargs["span_vals"]
assert shape[span_key0] == expected0
assert shape[span_key1] == expected1
assert shape[span_key1] == expected1