Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add initial TextBox widget testing #20451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions 25 lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,31 @@ def test_CheckButtons():
check.disconnect(cid)


def test_TextBox():
from unittest.mock import Mock
submit_event = Mock()
text_change_event = Mock()
ax = get_ax()

tool = widgets.TextBox(ax, 'Evaluate')
tool.on_submit(submit_event)
tool.on_text_change(text_change_event)
tool.set_val('x**2')

assert tool.text == 'x**2'
assert text_change_event.call_count == 1

tool.begin_typing(tool.text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really make sense to enter text into the box, and not verify that that actually ended up in the box, but instead, replace the text entirely on the submit handler.

If you want to verify that the handlers were called, then set a global, or use a Mock object that counts calls. And to verify that the setters work, just call them directly (and assert a check after.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thank you so much, I have modified according to your suggestions.

tool.stop_typing()

assert submit_event.call_count == 2
do_event(tool, '_click')
do_event(tool, '_keypress', key='+')
do_event(tool, '_keypress', key='5')

assert text_change_event.call_count == 3


@image_comparison(['check_radio_buttons.png'], style='mpl20', remove_text=True)
def test_check_radio_buttons_image():
# Remove this line when this test image is regenerated.
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.