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

Skip to content

Commit a669e0e

Browse files
committed
Updated host + parasite axes picking tests.
1 parent ed7285e commit a669e0e

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import numpy as np
2727

28+
import pytest
29+
2830

2931
@image_comparison(baseline_images=['divider_append_axes'])
3032
def test_divider_append_axes():
@@ -359,22 +361,29 @@ class TestPickingCallbacksOverlap(object):
359361
# In each case we expect that both rectangles are picked if we click on the
360362
# small one and only the big one is picked if we click on the big one.
361363
# Also tests picking on normal axes ("gca") as a control.
362-
def setUp(self):
363-
self.q = six.Queue()
364+
365+
@pytest.fixture(autouse=True)
366+
def setup(self):
367+
self.q = six.moves.queue.Queue()
364368
self.big = plt.Rectangle((0.25, 0.25), 0.5, 0.5, picker=5)
365369
self.small = plt.Rectangle((0.4, 0.4), 0.2, 0.2, facecolor="r",
366370
picker=5)
367371
plt.gcf().canvas.mpl_connect('pick_event', self.on_pick)
372+
368373
def on_pick(self, event):
369374
self.q.put(event)
370-
def test_picking_simple(self):
371-
# Configurations here are of the form: ( big_on_axes, small_on_axes )
372-
for rectangles_on_axes in [ ("gca", "gca"), ("host", "host"),
373-
("host", "parasite"), ("parasite", "host"),
374-
("parasite", "parasite") ]:
375-
for click_on in [ "big", "small" ]:
376-
yield self.run, rectangles_on_axes, click_on
377-
def run(self, rectangles_on_axes, click_on):
375+
376+
@pytest.mark.parametrize("click_on", [ "big", "small" ])
377+
@pytest.mark.parametrize("big_on_axes,small_on_axes", [
378+
("gca", "gca"),
379+
("host", "host"),
380+
("host", "parasite"),
381+
("parasite", "host"),
382+
("parasite", "parasite")
383+
])
384+
def test_picking_simple(self, big_on_axes, small_on_axes, click_on):
385+
# Shortcut
386+
rectangles_on_axes = (big_on_axes, small_on_axes)
378387
# Axes setup
379388
axes = { "gca": None, "host": None, "parasite": None }
380389
if "gca" in rectangles_on_axes:
@@ -383,7 +392,6 @@ def run(self, rectangles_on_axes, click_on):
383392
axes["host"] = host_subplot(111)
384393
axes["parasite"] = axes["host"].twin()
385394
# Add rectangles to axes
386-
(big_on_axes, small_on_axes) = rectangles_on_axes
387395
axes[big_on_axes].add_patch(self.big)
388396
axes[small_on_axes].add_patch(self.small)
389397
# Simulate picking with click mouse event
@@ -393,15 +401,15 @@ def run(self, rectangles_on_axes, click_on):
393401
else:
394402
click_axes = axes[small_on_axes]
395403
axes_coords = (0.5, 0.5)
396-
# In reality, mouse events never happen on parasite axes, only host axes
404+
# In reality mouse events never happen on parasite axes, only host axes
397405
if click_axes is axes["parasite"]:
398406
click_axes = axes["host"]
399407
(x, y) = click_axes.transAxes.transform(axes_coords)
400408
m = MouseEvent("button_press_event", click_axes.figure.canvas, x, y,
401409
button=1)
402410
click_axes.pick(m)
403-
# Wait at most a second for events; actual waiting only happens if
404-
# something is wrong and tests fail, this won't slow down normal testing
411+
# Wait at most a second for events; actual waiting only happens if sth.
412+
# is wrong and tests fail, so this won't slow down normal testing
405413
n_events = 2 if click_on == "small" else 1
406414
event_rects = []
407415
for i in range(n_events):

0 commit comments

Comments
 (0)