Skip to content

Commit 077393e

Browse files
authored
Merge pull request matplotlib#20451 from dmatos2012/testcov_textbox
Add initial TextBox widget testing
2 parents af17a9b + db72f7f commit 077393e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,31 @@ def test_CheckButtons():
254254
check.disconnect(cid)
255255

256256

257+
def test_TextBox():
258+
from unittest.mock import Mock
259+
submit_event = Mock()
260+
text_change_event = Mock()
261+
ax = get_ax()
262+
263+
tool = widgets.TextBox(ax, 'Evaluate')
264+
tool.on_submit(submit_event)
265+
tool.on_text_change(text_change_event)
266+
tool.set_val('x**2')
267+
268+
assert tool.text == 'x**2'
269+
assert text_change_event.call_count == 1
270+
271+
tool.begin_typing(tool.text)
272+
tool.stop_typing()
273+
274+
assert submit_event.call_count == 2
275+
do_event(tool, '_click')
276+
do_event(tool, '_keypress', key='+')
277+
do_event(tool, '_keypress', key='5')
278+
279+
assert text_change_event.call_count == 3
280+
281+
257282
@image_comparison(['check_radio_buttons.png'], style='mpl20', remove_text=True)
258283
def test_check_radio_buttons_image():
259284
# Remove this line when this test image is regenerated.

0 commit comments

Comments
 (0)