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

Skip to content

Commit 79ce193

Browse files
committed
Updated host + parasite axes picking tests.
1 parent 79643e5 commit 79ce193

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import numpy as np
2121

22+
import pytest
23+
2224

2325
@image_comparison(baseline_images=['divider_append_axes'])
2426
def test_divider_append_axes():
@@ -173,6 +175,7 @@ def test_zooming_with_inverted_axes():
173175
inset_ax = zoomed_inset_axes(ax, zoom=2.5, loc=4)
174176
inset_ax.axis([1.4, 1.1, 1.4, 1.1])
175177

178+
176179
class TestPickingCallbacksOverlap(object):
177180
"""Test pick events on normal, host or parasite axes."""
178181
# Two rectangles are drawn and "clicked on", a small one and a big one
@@ -181,22 +184,29 @@ class TestPickingCallbacksOverlap(object):
181184
# In each case we expect that both rectangles are picked if we click on the
182185
# small one and only the big one is picked if we click on the big one.
183186
# Also tests picking on normal axes ("gca") as a control.
184-
def setUp(self):
185-
self.q = six.Queue()
187+
188+
@pytest.fixture(autouse=True)
189+
def setup(self):
190+
self.q = six.moves.queue.Queue()
186191
self.big = plt.Rectangle((0.25, 0.25), 0.5, 0.5, picker=5)
187192
self.small = plt.Rectangle((0.4, 0.4), 0.2, 0.2, facecolor="r",
188193
picker=5)
189194
plt.gcf().canvas.mpl_connect('pick_event', self.on_pick)
195+
190196
def on_pick(self, event):
191197
self.q.put(event)
192-
def test_picking_simple(self):
193-
# Configurations here are of the form: ( big_on_axes, small_on_axes )
194-
for rectangles_on_axes in [ ("gca", "gca"), ("host", "host"),
195-
("host", "parasite"), ("parasite", "host"),
196-
("parasite", "parasite") ]:
197-
for click_on in [ "big", "small" ]:
198-
yield self.run, rectangles_on_axes, click_on
199-
def run(self, rectangles_on_axes, click_on):
198+
199+
@pytest.mark.parametrize("click_on", [ "big", "small" ])
200+
@pytest.mark.parametrize("big_on_axes,small_on_axes", [
201+
("gca", "gca"),
202+
("host", "host"),
203+
("host", "parasite"),
204+
("parasite", "host"),
205+
("parasite", "parasite")
206+
])
207+
def test_picking_simple(self, big_on_axes, small_on_axes, click_on):
208+
# Shortcut
209+
rectangles_on_axes = (big_on_axes, small_on_axes)
200210
# Axes setup
201211
axes = { "gca": None, "host": None, "parasite": None }
202212
if "gca" in rectangles_on_axes:
@@ -205,7 +215,6 @@ def run(self, rectangles_on_axes, click_on):
205215
axes["host"] = host_subplot(111)
206216
axes["parasite"] = axes["host"].twin()
207217
# Add rectangles to axes
208-
(big_on_axes, small_on_axes) = rectangles_on_axes
209218
axes[big_on_axes].add_patch(self.big)
210219
axes[small_on_axes].add_patch(self.small)
211220
# Simulate picking with click mouse event
@@ -215,15 +224,15 @@ def run(self, rectangles_on_axes, click_on):
215224
else:
216225
click_axes = axes[small_on_axes]
217226
axes_coords = (0.5, 0.5)
218-
# In reality, mouse events never happen on parasite axes, only host axes
227+
# In reality mouse events never happen on parasite axes, only host axes
219228
if click_axes is axes["parasite"]:
220229
click_axes = axes["host"]
221230
(x, y) = click_axes.transAxes.transform(axes_coords)
222231
m = MouseEvent("button_press_event", click_axes.figure.canvas, x, y,
223232
button=1)
224233
click_axes.pick(m)
225-
# Wait at most a second for events; actual waiting only happens if
226-
# something is wrong and tests fail, this won't slow down normal testing
234+
# Wait at most a second for events; actual waiting only happens if sth.
235+
# is wrong and tests fail, so this won't slow down normal testing
227236
n_events = 2 if click_on == "small" else 1
228237
event_rects = []
229238
for i in range(n_events):
@@ -232,4 +241,3 @@ def run(self, rectangles_on_axes, click_on):
232241
assert self.big in event_rects
233242
if click_on == "small":
234243
assert self.small in event_rects
235-

0 commit comments

Comments
 (0)