@@ -1686,6 +1686,52 @@ def test_polygon_selector_box(ax):
1686
1686
tool ._box .extents , (20.0 , 40.0 , 30.0 , 40.0 ))
1687
1687
1688
1688
1689
+ def test_polygon_selector_clear_method (ax ):
1690
+ onselect = mock .Mock (spec = noop , return_value = None )
1691
+ tool = widgets .PolygonSelector (ax , onselect )
1692
+
1693
+ event_sequence = [
1694
+ * polygon_place_vertex (50 , 50 ),
1695
+ * polygon_place_vertex (150 , 50 ),
1696
+ * polygon_place_vertex (50 , 150 ),
1697
+ * polygon_place_vertex (50 , 50 ),
1698
+ ]
1699
+ expected_result = [(50 , 50 ), (150 , 50 ), (50 , 150 ), (50 , 50 )]
1700
+
1701
+ for (etype , event_args ) in event_sequence :
1702
+ do_event (tool , etype , ** event_args )
1703
+
1704
+ artist = tool ._selection_artist
1705
+
1706
+ assert tool ._selection_completed
1707
+ assert tool .get_visible ()
1708
+ assert artist .get_visible ()
1709
+ np .testing .assert_equal (artist .get_xydata (), expected_result )
1710
+ assert onselect .call_args == ((expected_result [:- 1 ],), {})
1711
+
1712
+ tool .clear ()
1713
+ assert not tool ._selection_completed
1714
+ np .testing .assert_equal (artist .get_xydata (), [(0 , 0 )])
1715
+
1716
+ # Do another cycle of events to make sure we can
1717
+ event_sequence = [
1718
+ * polygon_place_vertex (50 , 50 ),
1719
+ * polygon_place_vertex (100 , 50 ),
1720
+ * polygon_place_vertex (50 , 150 ),
1721
+ * polygon_place_vertex (50 , 50 ),
1722
+ ]
1723
+ expected_result2 = [(50 , 50 ), (100 , 50 ), (50 , 150 ), (50 , 50 )]
1724
+
1725
+ for (etype , event_args ) in event_sequence :
1726
+ do_event (tool , etype , ** event_args )
1727
+
1728
+ assert tool ._selection_completed
1729
+ assert tool .get_visible ()
1730
+ assert artist .get_visible ()
1731
+ np .testing .assert_equal (artist .get_xydata (), expected_result2 )
1732
+ assert onselect .call_args == ((expected_result2 [:- 1 ],), {})
1733
+
1734
+
1689
1735
@pytest .mark .parametrize ("horizOn" , [False , True ])
1690
1736
@pytest .mark .parametrize ("vertOn" , [False , True ])
1691
1737
def test_MultiCursor (horizOn , vertOn ):
0 commit comments