Skip to content

Commit 139484a

Browse files
committed
Add some tests for minspan{x,y} in RectangleSelector
1 parent bf3c651 commit 139484a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lib/matplotlib/tests/test_widgets.py

+40
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,46 @@ def test_rectangle_selector():
5959
check_rectangle(props=dict(fill=True))
6060

6161

62+
@pytest.mark.parametrize('spancoords', ['data', 'pixels'])
63+
@pytest.mark.parametrize('minspanx, x1', [[0, 10], [1, 10.5]])
64+
@pytest.mark.parametrize('minspany, y1', [[0, 10], [1, 10.5]])
65+
def test_rectangle_minspan(spancoords, minspanx, x1, minspany, y1):
66+
ax = get_ax()
67+
ax._n_onselect = 0
68+
69+
def onselect(epress, erelease):
70+
ax._n_onselect += 1
71+
ax._epress = epress
72+
ax._erelease = erelease
73+
74+
x0, y0 = (10, 10)
75+
if spancoords == 'pixels':
76+
minspanx, minspany = (ax.transData.transform((x1, y1)) -
77+
ax.transData.transform((x0, y0)))
78+
79+
tool = widgets.RectangleSelector(ax, onselect, interactive=True,
80+
spancoords=spancoords,
81+
minspanx=minspanx, minspany=minspany)
82+
# Too small to create a selector
83+
click_and_drag(tool, start=(x0, x1), end=(y0, y1))
84+
assert not tool._selection_completed
85+
assert ax._n_onselect == 0
86+
87+
click_and_drag(tool, start=(20, 20), end=(30, 30))
88+
assert tool._selection_completed
89+
assert ax._n_onselect == 1
90+
91+
# Too small to create a selector. Should clear exising selector, and
92+
# trigger onselect because there was a pre-exisiting selector
93+
click_and_drag(tool, start=(x0, y0), end=(x1, y1))
94+
assert not tool._selection_completed
95+
assert ax._n_onselect == 2
96+
assert ax._epress.xdata == x0
97+
assert ax._epress.ydata == y0
98+
assert ax._erelease.xdata == x1
99+
assert ax._erelease.ydata == y1
100+
101+
62102
@pytest.mark.parametrize('drag_from_anywhere, new_center',
63103
[[True, (60, 75)],
64104
[False, (30, 20)]])

0 commit comments

Comments
 (0)