19
19
20
20
import numpy as np
21
21
22
+ import pytest
23
+
22
24
23
25
@image_comparison (baseline_images = ['divider_append_axes' ])
24
26
def test_divider_append_axes ():
@@ -173,6 +175,7 @@ def test_zooming_with_inverted_axes():
173
175
inset_ax = zoomed_inset_axes (ax , zoom = 2.5 , loc = 4 )
174
176
inset_ax .axis ([1.4 , 1.1 , 1.4 , 1.1 ])
175
177
178
+
176
179
class TestPickingCallbacksOverlap (object ):
177
180
"""Test pick events on normal, host or parasite axes."""
178
181
# Two rectangles are drawn and "clicked on", a small one and a big one
@@ -181,22 +184,29 @@ class TestPickingCallbacksOverlap(object):
181
184
# In each case we expect that both rectangles are picked if we click on the
182
185
# small one and only the big one is picked if we click on the big one.
183
186
# 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 ()
186
191
self .big = plt .Rectangle ((0.25 , 0.25 ), 0.5 , 0.5 , picker = 5 )
187
192
self .small = plt .Rectangle ((0.4 , 0.4 ), 0.2 , 0.2 , facecolor = "r" ,
188
193
picker = 5 )
189
194
plt .gcf ().canvas .mpl_connect ('pick_event' , self .on_pick )
195
+
190
196
def on_pick (self , event ):
191
197
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 )
200
210
# Axes setup
201
211
axes = { "gca" : None , "host" : None , "parasite" : None }
202
212
if "gca" in rectangles_on_axes :
@@ -205,7 +215,6 @@ def run(self, rectangles_on_axes, click_on):
205
215
axes ["host" ] = host_subplot (111 )
206
216
axes ["parasite" ] = axes ["host" ].twin ()
207
217
# Add rectangles to axes
208
- (big_on_axes , small_on_axes ) = rectangles_on_axes
209
218
axes [big_on_axes ].add_patch (self .big )
210
219
axes [small_on_axes ].add_patch (self .small )
211
220
# Simulate picking with click mouse event
@@ -215,15 +224,15 @@ def run(self, rectangles_on_axes, click_on):
215
224
else :
216
225
click_axes = axes [small_on_axes ]
217
226
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
219
228
if click_axes is axes ["parasite" ]:
220
229
click_axes = axes ["host" ]
221
230
(x , y ) = click_axes .transAxes .transform (axes_coords )
222
231
m = MouseEvent ("button_press_event" , click_axes .figure .canvas , x , y ,
223
232
button = 1 )
224
233
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
227
236
n_events = 2 if click_on == "small" else 1
228
237
event_rects = []
229
238
for i in range (n_events ):
@@ -232,4 +241,3 @@ def run(self, rectangles_on_axes, click_on):
232
241
assert self .big in event_rects
233
242
if click_on == "small" :
234
243
assert self .small in event_rects
235
-
0 commit comments