Skip to content

Commit 9fae7a4

Browse files
nicholas-esterernicolaskruchten
authored andcommitted
tests for selecting annotation-like objects with integer
string doesn't make sense in this case as they don't have a "type" key.
1 parent d4302cc commit 9fae7a4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import plotly.graph_objs as go
77
from plotly.subplots import make_subplots
8+
import pytest
89

910

1011
class TestSelectForEachUpdateAnnotations(TestCase):
@@ -348,3 +349,26 @@ def test_no_exclude_empty_subplots():
348349
assert fig.layout[k][1]["xref"] == "x2" and fig.layout[k][1]["yref"] == "y2"
349350
assert fig.layout[k][2]["xref"] == "x3" and fig.layout[k][2]["yref"] == "y3"
350351
assert fig.layout[k][3]["xref"] == "x4" and fig.layout[k][3]["yref"] == "y4"
352+
353+
354+
@pytest.fixture
355+
def select_annotations_integer():
356+
fig = make_subplots(2, 3)
357+
fig.add_annotation(row=1, col=2, text="B")
358+
fig.add_annotation(row=2, col=2, text="A")
359+
fig.add_annotation(row=2, col=2, text="B")
360+
fig.add_annotation(row=2, col=2, text="AB")
361+
fig.add_annotation(text="hello")
362+
return fig
363+
364+
365+
def test_select_annotations_integer(select_annotations_integer):
366+
fig = select_annotations_integer
367+
anns = list(fig.select_annotations(selector=-1))
368+
assert (len(anns) == 1) and (anns[0]["text"] == "hello")
369+
anns = list(fig.select_annotations(row=2, col=2, selector=-1))
370+
assert (len(anns) == 1) and anns[0]["text"] == "AB"
371+
anns = list(fig.select_annotations(row=1, col=2, selector=-1))
372+
assert (len(anns) == 1) and anns[0]["text"] == "B"
373+
with pytest.raises(IndexError):
374+
fig.select_annotations(row=2, col=2, selector=3)

0 commit comments

Comments
 (0)