Skip to content

Commit 4fb7388

Browse files
jayzhou2309claude
andcommitted
Add failing test for add_annotation rebuilding existing annotations
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d586d22 commit 4fb7388

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎tests/test_core/test_update_objects/test_update_annotations.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import types
22
from unittest import TestCase
3+
from unittest.mock import MagicMock
34

45
import plotly.graph_objs as go
56
from plotly.subplots import make_subplots
@@ -428,3 +429,35 @@ def test_select_annotations_integer(select_annotations_integer):
428429
assert (len(anns) == 1) and anns[0]["text"] == "B"
429430
with pytest.raises(IndexError):
430431
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

Comments
 (0)