|
1 | 1 | import types |
2 | 2 | from unittest import TestCase |
| 3 | +from unittest.mock import MagicMock |
3 | 4 |
|
4 | 5 | import plotly.graph_objs as go |
5 | 6 | from plotly.subplots import make_subplots |
@@ -428,3 +429,35 @@ def test_select_annotations_integer(select_annotations_integer): |
428 | 429 | assert (len(anns) == 1) and anns[0]["text"] == "B" |
429 | 430 | with pytest.raises(IndexError): |
430 | 431 | fig.select_annotations(row=2, col=2, selector=3) |
| 432 | + |
| 433 | + |
| 434 | +def test_add_annotation_keeps_existing_annotations(): |
| 435 | + fig = go.Figure() |
| 436 | + fig.add_annotation(text="first") |
| 437 | + first = fig.layout.annotations[0] |
| 438 | + |
| 439 | + fig.add_annotation(text="second") |
| 440 | + |
| 441 | + assert fig.layout.annotations[0] is first |
| 442 | + first.text = "edited" |
| 443 | + assert fig.to_dict()["layout"]["annotations"] == [ |
| 444 | + {"text": "edited"}, |
| 445 | + {"text": "second"}, |
| 446 | + ] |
| 447 | + |
| 448 | + |
| 449 | +def test_add_shape_sends_full_array_relayout(): |
| 450 | + fig = go.Figure() |
| 451 | + fig.add_shape(type="line", x0=0, x1=1) |
| 452 | + fig._send_relayout_msg = MagicMock() |
| 453 | + |
| 454 | + fig.add_shape(type="rect", x0=2, x1=3) |
| 455 | + |
| 456 | + fig._send_relayout_msg.assert_called_once_with( |
| 457 | + { |
| 458 | + "shapes": [ |
| 459 | + {"type": "line", "x0": 0, "x1": 1}, |
| 460 | + {"type": "rect", "x0": 2, "x1": 3}, |
| 461 | + ] |
| 462 | + } |
| 463 | + ) |
0 commit comments