@@ -18,38 +18,53 @@ def test_signal_blocker_exception(qtbot):
18
18
qtbot .waitSignal (None , None ).wait ()
19
19
20
20
21
- def explicit_wait (qtbot , signal , timeout ):
21
+ def explicit_wait (qtbot , signal , timeout , raising , raises ):
22
22
"""
23
23
Explicit wait for the signal using blocker API.
24
24
"""
25
- blocker = qtbot .waitSignal (signal , timeout )
25
+ blocker = qtbot .waitSignal (signal , timeout , raising = raising )
26
26
assert not blocker .signal_triggered
27
- blocker .wait ()
27
+ if raises :
28
+ with pytest .raises (qtbot .SignalTimeout ):
29
+ blocker .wait ()
30
+ else :
31
+ blocker .wait ()
28
32
return blocker
29
33
30
34
31
- def context_manager_wait (qtbot , signal , timeout ):
35
+ def context_manager_wait (qtbot , signal , timeout , raising , raises ):
32
36
"""
33
37
Waiting for signal using context manager API.
34
38
"""
35
- with qtbot .waitSignal (signal , timeout ) as blocker :
36
- pass
39
+ if raises :
40
+ with pytest .raises (qtbot .SignalTimeout ):
41
+ with qtbot .waitSignal (signal , timeout , raising = raising ) as blocker :
42
+ pass
43
+ else :
44
+ with qtbot .waitSignal (signal , timeout , raising = raising ) as blocker :
45
+ pass
37
46
return blocker
38
47
39
48
40
49
@pytest .mark .parametrize (
41
- ('wait_function' , 'emit_delay' , 'timeout' , 'expected_signal_triggered' ),
50
+ ('wait_function' , 'emit_delay' , 'timeout' , 'expected_signal_triggered' ,
51
+ 'raising' ),
42
52
[
43
- (explicit_wait , 500 , 2000 , True ),
44
- (explicit_wait , 500 , None , True ),
45
- (context_manager_wait , 500 , 2000 , True ),
46
- (context_manager_wait , 500 , None , True ),
47
- (explicit_wait , 2000 , 500 , False ),
48
- (context_manager_wait , 2000 , 500 , False ),
53
+ (explicit_wait , 500 , 2000 , True , False ),
54
+ (explicit_wait , 500 , None , True , False ),
55
+ (context_manager_wait , 500 , 2000 , True , False ),
56
+ (context_manager_wait , 500 , None , True , False ),
57
+ (explicit_wait , 2000 , 500 , False , False ),
58
+ (context_manager_wait , 2000 , 500 , False , False ),
59
+
60
+ (explicit_wait , 2000 , 500 , False , True ),
61
+ (context_manager_wait , 2000 , 500 , False , True ),
62
+ (explicit_wait , 2000 , 500 , False , True ),
63
+ (context_manager_wait , 2000 , 500 , False , True ),
49
64
] * 2 # Running all tests twice to catch a QTimer segfault, see #42/#43.
50
65
)
51
66
def test_signal_triggered (qtbot , wait_function , emit_delay , timeout ,
52
- expected_signal_triggered ):
67
+ expected_signal_triggered , raising ):
53
68
"""
54
69
Testing for a signal in different conditions, ensuring we are obtaining
55
70
the expected results.
@@ -62,7 +77,9 @@ def test_signal_triggered(qtbot, wait_function, emit_delay, timeout,
62
77
63
78
# block signal until either signal is emitted or timeout is reached
64
79
start_time = time .time ()
65
- blocker = wait_function (qtbot , signaller .signal , timeout )
80
+ raises = raising and not expected_signal_triggered
81
+ blocker = wait_function (qtbot , signaller .signal , timeout , raising = raising ,
82
+ raises = raises )
66
83
67
84
# Check that event loop exited.
68
85
assert not blocker ._loop .isRunning ()
0 commit comments