@@ -621,27 +621,36 @@ def test_rectangle_selector_ignore_outside(ax, ignore_event_outside):
621621 ('horizontal' , False , dict (interactive = True )),
622622])
623623def test_span_selector (ax , orientation , onmove_callback , kwargs ):
624- onselect = mock .Mock (spec = noop , return_value = None )
625- onmove = mock .Mock (spec = noop , return_value = None )
626- if onmove_callback :
627- kwargs ['onmove_callback' ] = onmove
628-
629- # While at it, also test that span selectors work in the presence of twin axes on
630- # top of the axes that contain the selector. Note that we need to unforce the axes
631- # aspect here, otherwise the twin axes forces the original axes' limits (to respect
632- # aspect=1) which makes some of the values below go out of bounds.
624+ # Also test that span selectors work in the presence of twin axes or for
625+ # outside-inset axes on top of the axes that contain the selector. Note
626+ # that we need to unforce the axes aspect here, otherwise the twin axes
627+ # forces the original axes' limits (to respect aspect=1) which makes some
628+ # of the values below go out of bounds.
633629 ax .set_aspect ("auto" )
634- tax = ax .twinx ()
635-
636- tool = widgets .SpanSelector (ax , onselect , orientation , ** kwargs )
637- MouseEvent ._from_ax_coords ("button_press_event" , ax , (100 , 100 ), 1 )._process ()
638- # move outside of axis
639- MouseEvent ._from_ax_coords ("motion_notify_event" , ax , (199 , 199 ), 1 )._process ()
640- MouseEvent ._from_ax_coords ("button_release_event" , ax , (250 , 250 ), 1 )._process ()
641-
642- onselect .assert_called_once_with (100 , 199 )
643- if onmove_callback :
644- onmove .assert_called_once_with (100 , 199 )
630+ ax .twinx ()
631+ child = ax .inset_axes ([0 , 1 , 1 , 1 ], xlim = (0 , 200 ), ylim = (0 , 200 ))
632+
633+ for target in [ax , child ]:
634+ selected = []
635+ def onselect (* args ): selected .append (args )
636+ moved = []
637+ def onmove (* args ): moved .append (args )
638+ if onmove_callback :
639+ kwargs ['onmove_callback' ] = onmove
640+
641+ tool = widgets .SpanSelector (target , onselect , orientation , ** kwargs )
642+ MouseEvent ._from_ax_coords (
643+ "button_press_event" , target , (100 , 100 ), 1 )._process ()
644+ # move outside of axis
645+ MouseEvent ._from_ax_coords (
646+ "motion_notify_event" , target , (199 , 199 ), 1 )._process ()
647+ MouseEvent ._from_ax_coords (
648+ "button_release_event" , target , (250 , 250 ), 1 )._process ()
649+
650+ # tol is set by pixel size (~100 pixels & span of 200 data units)
651+ assert_allclose (selected , [(100 , 199 )], atol = .5 )
652+ if onmove_callback :
653+ assert_allclose (moved , [(100 , 199 )], atol = .5 )
645654
646655
647656@pytest .mark .parametrize ('interactive' , [True , False ])
0 commit comments