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

Commit d7e3383

Browse filesBrowse files
authored
Merge pull request #22154 from dstansby/minspan-tests
Add some tests for minspan{x,y} in RectangleSelector
2 parents 1fb8c74 + b093665 commit d7e3383
Copy full SHA for d7e3383

File tree

1 file changed

+41
-0
lines changed
Filter options

1 file changed

+41
-0
lines changed

‎lib/matplotlib/tests/test_widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_widgets.py
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,47 @@ def test_rectangle_selector():
6464
check_rectangle(props=dict(fill=True))
6565

6666

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.