From b09366554c49e26c329e0aa2549d0756ab9bc809 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 17 Jan 2022 11:10:19 +0000 Subject: [PATCH] Add some tests for minspan{x,y} in RectangleSelector --- lib/matplotlib/tests/test_widgets.py | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lib/matplotlib/tests/test_widgets.py b/lib/matplotlib/tests/test_widgets.py index a9e04fd89c0e..9edfdea73e0a 100644 --- a/lib/matplotlib/tests/test_widgets.py +++ b/lib/matplotlib/tests/test_widgets.py @@ -59,6 +59,47 @@ def test_rectangle_selector(): check_rectangle(props=dict(fill=True)) +@pytest.mark.parametrize('spancoords', ['data', 'pixels']) +@pytest.mark.parametrize('minspanx, x1', [[0, 10], [1, 10.5], [1, 11]]) +@pytest.mark.parametrize('minspany, y1', [[0, 10], [1, 10.5], [1, 11]]) +def test_rectangle_minspan(spancoords, minspanx, x1, minspany, y1): + ax = get_ax() + # attribute to track number of onselect calls + ax._n_onselect = 0 + + def onselect(epress, erelease): + ax._n_onselect += 1 + ax._epress = epress + ax._erelease = erelease + + x0, y0 = (10, 10) + if spancoords == 'pixels': + minspanx, minspany = (ax.transData.transform((x1, y1)) - + ax.transData.transform((x0, y0))) + + tool = widgets.RectangleSelector(ax, onselect, interactive=True, + spancoords=spancoords, + minspanx=minspanx, minspany=minspany) + # Too small to create a selector + click_and_drag(tool, start=(x0, x1), end=(y0, y1)) + assert not tool._selection_completed + assert ax._n_onselect == 0 + + click_and_drag(tool, start=(20, 20), end=(30, 30)) + assert tool._selection_completed + assert ax._n_onselect == 1 + + # Too small to create a selector. Should clear exising selector, and + # trigger onselect because there was a pre-exisiting selector + click_and_drag(tool, start=(x0, y0), end=(x1, y1)) + assert not tool._selection_completed + assert ax._n_onselect == 2 + assert ax._epress.xdata == x0 + assert ax._epress.ydata == y0 + assert ax._erelease.xdata == x1 + assert ax._erelease.ydata == y1 + + @pytest.mark.parametrize('drag_from_anywhere, new_center', [[True, (60, 75)], [False, (30, 20)]]) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy