Skip to content

Add tests for ginput and waitforbuttonpress. #20189

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 1 commit into from
May 12, 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
32 changes: 32 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io
from pathlib import Path
import platform
from threading import Timer
from types import SimpleNamespace
import warnings

Expand Down Expand Up @@ -1082,3 +1083,34 @@ def test_add_axes_kwargs():
assert ax1.name == 'rectilinear'
assert ax1 is not ax
plt.close()


def test_ginput(recwarn): # recwarn undoes warn filters at exit.
warnings.filterwarnings("ignore", "cannot show the figure")
fig, ax = plt.subplots()

def single_press():
fig.canvas.button_press_event(*ax.transData.transform((.1, .2)), 1)

Timer(.1, single_press).start()
assert fig.ginput() == [(.1, .2)]

def multi_presses():
fig.canvas.button_press_event(*ax.transData.transform((.1, .2)), 1)
fig.canvas.key_press_event("backspace")
fig.canvas.button_press_event(*ax.transData.transform((.3, .4)), 1)
fig.canvas.button_press_event(*ax.transData.transform((.5, .6)), 1)
fig.canvas.button_press_event(*ax.transData.transform((0, 0)), 2)

Timer(.1, multi_presses).start()
np.testing.assert_allclose(fig.ginput(3), [(.3, .4), (.5, .6)])


def test_waitforbuttonpress(recwarn): # recwarn undoes warn filters at exit.
warnings.filterwarnings("ignore", "cannot show the figure")
fig = plt.figure()
assert fig.waitforbuttonpress(timeout=.1) is None
Timer(.1, fig.canvas.key_press_event, ("z",)).start()
assert fig.waitforbuttonpress() is True
Timer(.1, fig.canvas.button_press_event, (0, 0, 1)).start()
assert fig.waitforbuttonpress() is False