Skip to content

Commit 56fc082

Browse files
committed
Add test for PolygonSelector.clear()
1 parent ef0a291 commit 56fc082

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,52 @@ def test_polygon_selector_box(ax):
16861686
tool._box.extents, (20.0, 40.0, 30.0, 40.0))
16871687

16881688

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+
16891735
@pytest.mark.parametrize("horizOn", [False, True])
16901736
@pytest.mark.parametrize("vertOn", [False, True])
16911737
def test_MultiCursor(horizOn, vertOn):

0 commit comments

Comments
 (0)