Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a9c45c3

Browse files
committed
Apply code review suggestions
1 parent 56fc082 commit a9c45c3

File tree

2 files changed

+15
-39
lines changed

2 files changed

+15
-39
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,46 +1690,23 @@ def test_polygon_selector_clear_method(ax):
16901690
onselect = mock.Mock(spec=noop, return_value=None)
16911691
tool = widgets.PolygonSelector(ax, onselect)
16921692

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],), {})
1693+
for result in ([(50, 50), (150, 50), (50, 150), (50, 50)],
1694+
[(50, 50), (100, 50), (50, 150), (50, 50)]):
1695+
for x, y in result:
1696+
for etype, event_args in polygon_place_vertex(x, y):
1697+
do_event(tool, etype, **event_args)
17111698

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)]
1699+
artist = tool._selection_artist
17241700

1725-
for (etype, event_args) in event_sequence:
1726-
do_event(tool, etype, **event_args)
1701+
assert tool._selection_completed
1702+
assert tool.get_visible()
1703+
assert artist.get_visible()
1704+
np.testing.assert_equal(artist.get_xydata(), result)
1705+
assert onselect.call_args == ((result[:-1],), {})
17271706

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],), {})
1707+
tool.clear()
1708+
assert not tool._selection_completed
1709+
np.testing.assert_equal(artist.get_xydata(), [(0, 0)])
17331710

17341711

17351712
@pytest.mark.parametrize("horizOn", [False, True])

lib/matplotlib/widgets.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4142,8 +4142,7 @@ def _on_key_release(self, event):
41424142
self.set_visible(True)
41434143

41444144
def _draw_polygon_without_update(self):
4145-
"""Redraw the polygon based on the new vertex positions, no update().
4146-
"""
4145+
"""Redraw the polygon based on new vertex positions, no update()."""
41474146
xs, ys = zip(*self._xys) if self._xys else ([], [])
41484147
self._selection_artist.set_data(xs, ys)
41494148
self._update_box()

0 commit comments

Comments
 (0)