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

Skip to content

Commit b093665

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

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,47 @@ 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], [1, 11]])
64+
@pytest.mark.parametrize('minspany, y1', [[0, 10], [1, 10.5], [1, 11]])
65+
def test_rectangle_minspan(spancoords, minspanx, x1, minspany, y1):
66+
ax = get_ax()
67+
# attribute to track number of onselect calls
68+
ax._n_onselect = 0
69+
70+
def onselect(epress, erelease):
71+
ax._n_onselect += 1
72+
ax._epress = epress
73+
ax._erelease = erelease
74+
75+
x0, y0 = (10, 10)
76+
if spancoords == 'pixels':
77+
minspanx, minspany = (ax.transData.transform((x1, y1)) -
78+
ax.transData.transform((x0, y0)))
79+
80+
tool = widgets.RectangleSelector(ax, onselect, interactive=True,
81+
spancoords=spancoords,
82+
minspanx=minspanx, minspany=minspany)
83+
# Too small to create a selector
84+
click_and_drag(tool, start=(x0, x1), end=(y0, y1))
85+
assert not tool._selection_completed
86+
assert ax._n_onselect == 0
87+
88+
click_and_drag(tool, start=(20, 20), end=(30, 30))
89+
assert tool._selection_completed
90+
assert ax._n_onselect == 1
91+
92+
# Too small to create a selector. Should clear exising selector, and
93+
# trigger onselect because there was a pre-exisiting selector
94+
click_and_drag(tool, start=(x0, y0), end=(x1, y1))
95+
assert not tool._selection_completed
96+
assert ax._n_onselect == 2
97+
assert ax._epress.xdata == x0
98+
assert ax._epress.ydata == y0
99+
assert ax._erelease.xdata == x1
100+
assert ax._erelease.ydata == y1
101+
102+
62103
@pytest.mark.parametrize('drag_from_anywhere, new_center',
63104
[[True, (60, 75)],
64105
[False, (30, 20)]])

0 commit comments

Comments
 (0)