Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ea8f69

Browse files
committed
widgets: test _Buttons' callbacks
1 parent 5dee947 commit 8ea8f69

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

lib/matplotlib/tests/test_widgets.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,25 @@ def test_check_button_props(fig_test, fig_ref):
12191219
cb.set_check_props({**check_props, 's': (24 / 2)**2})
12201220

12211221

1222+
@pytest.mark.parametrize("widget", [widgets.RadioButtons, widgets.CheckButtons])
1223+
def test__buttons_callbacks(ax, widget):
1224+
"""Tests what https://github.com/matplotlib/matplotlib/pull/31031 fixed"""
1225+
on_clicked = mock.Mock(spec=noop, return_value=None)
1226+
button = widget(ax, ["Test Button"])
1227+
button.on_clicked(on_clicked)
1228+
MouseEvent._from_ax_coords(
1229+
"button_press_event",
1230+
ax,
1231+
ax.transData.inverted().transform(ax.transAxes.transform(
1232+
# (x, y) of the 0th button defined at
1233+
# `{Check,Radio}Buttons._init_props`
1234+
(0.15, 0.5),
1235+
)),
1236+
1,
1237+
)._process()
1238+
on_clicked.assert_called_once()
1239+
1240+
12221241
def test_slider_slidermin_slidermax_invalid():
12231242
fig, ax = plt.subplots()
12241243
# test min/max with floats

0 commit comments

Comments
 (0)