25
25
26
26
import numpy as np
27
27
28
+ import pytest
29
+
28
30
29
31
@image_comparison (baseline_images = ['divider_append_axes' ])
30
32
def test_divider_append_axes ():
@@ -359,22 +361,29 @@ class TestPickingCallbacksOverlap(object):
359
361
# In each case we expect that both rectangles are picked if we click on the
360
362
# small one and only the big one is picked if we click on the big one.
361
363
# 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 ()
364
368
self .big = plt .Rectangle ((0.25 , 0.25 ), 0.5 , 0.5 , picker = 5 )
365
369
self .small = plt .Rectangle ((0.4 , 0.4 ), 0.2 , 0.2 , facecolor = "r" ,
366
370
picker = 5 )
367
371
plt .gcf ().canvas .mpl_connect ('pick_event' , self .on_pick )
372
+
368
373
def on_pick (self , event ):
369
374
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 )
378
387
# Axes setup
379
388
axes = { "gca" : None , "host" : None , "parasite" : None }
380
389
if "gca" in rectangles_on_axes :
@@ -383,7 +392,6 @@ def run(self, rectangles_on_axes, click_on):
383
392
axes ["host" ] = host_subplot (111 )
384
393
axes ["parasite" ] = axes ["host" ].twin ()
385
394
# Add rectangles to axes
386
- (big_on_axes , small_on_axes ) = rectangles_on_axes
387
395
axes [big_on_axes ].add_patch (self .big )
388
396
axes [small_on_axes ].add_patch (self .small )
389
397
# Simulate picking with click mouse event
@@ -393,15 +401,15 @@ def run(self, rectangles_on_axes, click_on):
393
401
else :
394
402
click_axes = axes [small_on_axes ]
395
403
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
397
405
if click_axes is axes ["parasite" ]:
398
406
click_axes = axes ["host" ]
399
407
(x , y ) = click_axes .transAxes .transform (axes_coords )
400
408
m = MouseEvent ("button_press_event" , click_axes .figure .canvas , x , y ,
401
409
button = 1 )
402
410
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
405
413
n_events = 2 if click_on == "small" else 1
406
414
event_rects = []
407
415
for i in range (n_events ):
0 commit comments