1+ from contextlib import nullcontext
12import functools
23from unittest import mock
34
@@ -21,12 +22,22 @@ def ax():
2122 return get_ax ()
2223
2324
24- def check_rectangle (** kwargs ):
25- ax = get_ax ()
26-
25+ @pytest .mark .parametrize ('kwargs, warning_msg' , [
26+ (dict (), None ),
27+ (dict (drawtype = 'line' , useblit = False ),
28+ "Support for drawtype='line' is deprecated" ),
29+ (dict (useblit = True , button = 1 ), None ),
30+ (dict (drawtype = 'none' , minspanx = 10 , minspany = 10 ),
31+ "Support for drawtype='none' is deprecated" ),
32+ (dict (minspanx = 10 , minspany = 10 , spancoords = 'pixels' ), None ),
33+ (dict (props = dict (fill = True )), None ),
34+ ])
35+ def test_rectangle_selector (ax , kwargs , warning_msg ):
2736 onselect = mock .Mock (spec = noop , return_value = None )
2837
29- tool = widgets .RectangleSelector (ax , onselect , ** kwargs )
38+ with (pytest .warns (MatplotlibDeprecationWarning , match = warning_msg )
39+ if warning_msg else nullcontext ()):
40+ tool = widgets .RectangleSelector (ax , onselect , ** kwargs )
3041 do_event (tool , 'press' , xdata = 100 , ydata = 100 , button = 1 )
3142 do_event (tool , 'onmove' , xdata = 199 , ydata = 199 , button = 1 )
3243
@@ -48,25 +59,6 @@ def check_rectangle(**kwargs):
4859 assert kwargs == {}
4960
5061
51- def test_rectangle_selector ():
52- check_rectangle ()
53-
54- with pytest .warns (
55- MatplotlibDeprecationWarning ,
56- match = "Support for drawtype='line' is deprecated" ):
57- check_rectangle (drawtype = 'line' , useblit = False )
58-
59- check_rectangle (useblit = True , button = 1 )
60-
61- with pytest .warns (
62- MatplotlibDeprecationWarning ,
63- match = "Support for drawtype='none' is deprecated" ):
64- check_rectangle (drawtype = 'none' , minspanx = 10 , minspany = 10 )
65-
66- check_rectangle (minspanx = 10 , minspany = 10 , spancoords = 'pixels' )
67- check_rectangle (props = dict (fill = True ))
68-
69-
7062@pytest .mark .parametrize ('spancoords' , ['data' , 'pixels' ])
7163@pytest .mark .parametrize ('minspanx, x1' , [[0 , 10 ], [1 , 10.5 ], [1 , 11 ]])
7264@pytest .mark .parametrize ('minspany, y1' , [[0 , 10 ], [1 , 10.5 ], [1 , 11 ]])
@@ -607,15 +599,19 @@ def test_rectangle_selector_ignore_outside(ax, ignore_event_outside):
607599 assert tool .extents == (150.0 , 160.0 , 150.0 , 160.0 )
608600
609601
610- def check_span (* args , onmove_callback = True , ** kwargs ):
611- ax = get_ax ()
612-
602+ @pytest .mark .parametrize ('orientation, onmove_callback, kwargs' , [
603+ ('horizontal' , False , dict (minspan = 10 , useblit = True )),
604+ ('vertical' , True , dict (button = 1 )),
605+ ('horizontal' , False , dict (props = dict (fill = True ))),
606+ ('horizontal' , False , dict (interactive = True )),
607+ ])
608+ def test_span_selector (ax , orientation , onmove_callback , kwargs ):
613609 onselect = mock .Mock (spec = noop , return_value = None )
614610 onmove = mock .Mock (spec = noop , return_value = None )
615611 if onmove_callback :
616612 kwargs ['onmove_callback' ] = onmove
617613
618- tool = widgets .SpanSelector (ax , onselect , * args , ** kwargs )
614+ tool = widgets .SpanSelector (ax , onselect , orientation , ** kwargs )
619615 do_event (tool , 'press' , xdata = 100 , ydata = 100 , button = 1 )
620616 # move outside of axis
621617 do_event (tool , 'onmove' , xdata = 199 , ydata = 199 , button = 1 )
@@ -626,13 +622,6 @@ def check_span(*args, onmove_callback=True, **kwargs):
626622 onmove .assert_called_once_with (100 , 199 )
627623
628624
629- def test_span_selector ():
630- check_span ('horizontal' , minspan = 10 , useblit = True )
631- check_span ('vertical' , onmove_callback = True , button = 1 )
632- check_span ('horizontal' , props = dict (fill = True ))
633- check_span ('horizontal' , interactive = True )
634-
635-
636625@pytest .mark .parametrize ('interactive' , [True , False ])
637626def test_span_selector_onselect (ax , interactive ):
638627 onselect = mock .Mock (spec = noop , return_value = None )
@@ -948,9 +937,12 @@ def onselect(vmin, vmax):
948937 assert tool .extents == (17 , 35 )
949938
950939
951- def check_lasso_selector (** kwargs ):
952- ax = get_ax ()
953-
940+ @pytest .mark .parametrize ('kwargs' , [
941+ dict (),
942+ dict (useblit = False , props = dict (color = 'red' )),
943+ dict (useblit = True , button = 1 ),
944+ ])
945+ def test_lasso_selector (ax , kwargs ):
954946 onselect = mock .Mock (spec = noop , return_value = None )
955947
956948 tool = widgets .LassoSelector (ax , onselect , ** kwargs )
@@ -961,12 +953,6 @@ def check_lasso_selector(**kwargs):
961953 onselect .assert_called_once_with ([(100 , 100 ), (125 , 125 ), (150 , 150 )])
962954
963955
964- def test_lasso_selector ():
965- check_lasso_selector ()
966- check_lasso_selector (useblit = False , props = dict (color = 'red' ))
967- check_lasso_selector (useblit = True , button = 1 )
968-
969-
970956def test_CheckButtons (ax ):
971957 check = widgets .CheckButtons (ax , ('a' , 'b' , 'c' ), (True , False , True ))
972958 assert check .get_status () == [True , False , True ]
0 commit comments