|
5 | 5 |
|
6 | 6 | import plotly.graph_objs as go
|
7 | 7 | from plotly.subplots import make_subplots
|
| 8 | +import pytest |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class TestSelectForEachUpdateAnnotations(TestCase):
|
@@ -348,3 +349,26 @@ def test_no_exclude_empty_subplots():
|
348 | 349 | assert fig.layout[k][1]["xref"] == "x2" and fig.layout[k][1]["yref"] == "y2"
|
349 | 350 | assert fig.layout[k][2]["xref"] == "x3" and fig.layout[k][2]["yref"] == "y3"
|
350 | 351 | 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