@@ -23,42 +23,49 @@ def explicit_wait(qtbot, signal, timeout):
23
23
Explicit wait for the signal using blocker API.
24
24
"""
25
25
blocker = qtbot .waitSignal (signal , timeout )
26
- start_time = time . time ()
26
+ assert blocker . signal_triggered is None
27
27
blocker .wait ()
28
- return blocker . _loop , start_time
28
+ return blocker
29
29
30
30
31
31
def context_manager_wait (qtbot , signal , timeout ):
32
32
"""
33
33
Waiting for signal using context manager API.
34
34
"""
35
35
with qtbot .waitSignal (signal , timeout ) as blocker :
36
- start_time = time . time ()
37
- return blocker . _loop , start_time
36
+ pass
37
+ return blocker
38
38
39
39
40
40
@pytest .mark .parametrize (
41
- ('wait_function' , 'emit_delay' , 'timeout' ),
41
+ ('wait_function' , 'emit_delay' , 'timeout' , 'expected_signal_triggered' ),
42
42
[
43
- (explicit_wait , 500 , 2000 ),
44
- (explicit_wait , 500 , None ),
45
- (context_manager_wait , 500 , 2000 ),
46
- (context_manager_wait , 500 , None ),
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 ),
47
49
]
48
50
)
49
- def test_signal_triggered (qtbot , wait_function , emit_delay , timeout ):
51
+ def test_signal_triggered (qtbot , wait_function , emit_delay , timeout ,
52
+ expected_signal_triggered ):
50
53
"""
51
- Ensure that a signal being triggered before timeout expires makes the
52
- loop quitting early .
54
+ Testing for a signal in different conditions, ensuring we are obtaining
55
+ the expected results .
53
56
"""
54
57
signaller = Signaller ()
55
58
QtCore .QTimer .singleShot (emit_delay , signaller .signal .emit )
56
59
57
60
# block signal until either signal is emitted or timeout is reached
58
- loop , start_time = wait_function (qtbot , signaller .signal , timeout )
61
+ start_time = time .time ()
62
+ blocker = wait_function (qtbot , signaller .signal , timeout )
59
63
60
64
# Check that event loop exited.
61
- assert not loop .isRunning ()
65
+ assert not blocker ._loop .isRunning ()
66
+
67
+ # ensure that either signal was triggered or timeout occurred
68
+ assert blocker .signal_triggered == expected_signal_triggered
62
69
63
70
# Check that we exited by the earliest parameter; timeout = None means
64
71
# wait forever, so ensure we waited at most 4 times emit-delay
0 commit comments