@@ -50,31 +50,40 @@ def context_manager_wait(qtbot, signal, timeout, multiple, raising,
50
50
return blocker
51
51
52
52
53
+ def build_signal_tests_variants (params ):
54
+ """
55
+ Helper function to use with pytest's parametrize, to generate additional
56
+ combinations of parameters in a parametrize call:
57
+ - explicit wait and context-manager wait
58
+ - raising True and False (since we check for the correct behavior inside
59
+ each test).
60
+ """
61
+ result = []
62
+ for param in params :
63
+ for wait_function in (explicit_wait , context_manager_wait ):
64
+ for raising in (True , False ):
65
+ result .append (param + (wait_function , raising ))
66
+ return result
67
+
68
+
53
69
@pytest .mark .parametrize (
54
- ('wait_function' , 'emit_delay' , 'timeout' , 'expected_signal_triggered' ,
55
- 'raising' ),
56
- [
57
- (explicit_wait , 100 , 200 , True , False ),
58
- (explicit_wait , 100 , None , True , False ),
59
- (context_manager_wait , 100 , 200 , True , False ),
60
- (context_manager_wait , 100 , None , True , False ),
61
- (explicit_wait , 200 , 100 , False , False ),
62
- (context_manager_wait , 200 , 100 , False , False ),
63
-
64
- (explicit_wait , 200 , 100 , False , True ),
65
- (context_manager_wait , 200 , 100 , False , True ),
66
- (explicit_wait , 200 , 100 , False , True ),
67
- (context_manager_wait , 200 , 100 , False , True ),
68
- ]
70
+ ('delay' , 'timeout' , 'expected_signal_triggered' ,
71
+ 'wait_function' , 'raising' ),
72
+ build_signal_tests_variants ([
73
+ # delay, timeout, expected_signal_triggered
74
+ (100 , None , True ),
75
+ (100 , 200 , True ),
76
+ (200 , 100 , False ),
77
+ ])
69
78
)
70
- def test_signal_triggered (qtbot , single_shot , stop_watch , wait_function , emit_delay ,
79
+ def test_signal_triggered (qtbot , single_shot , stop_watch , wait_function , delay ,
71
80
timeout , expected_signal_triggered , raising ):
72
81
"""
73
82
Testing for a signal in different conditions, ensuring we are obtaining
74
83
the expected results.
75
84
"""
76
85
signaller = Signaller ()
77
- single_shot (signaller .signal , emit_delay )
86
+ single_shot (signaller .signal , delay )
78
87
79
88
should_raise = raising and not expected_signal_triggered
80
89
@@ -88,37 +97,33 @@ def test_signal_triggered(qtbot, single_shot, stop_watch, wait_function, emit_de
88
97
# ensure that either signal was triggered or timeout occurred
89
98
assert blocker .signal_triggered == expected_signal_triggered
90
99
91
- stop_watch .check (timeout , emit_delay )
100
+ stop_watch .check (timeout , delay )
92
101
93
102
94
103
@pytest .mark .parametrize (
95
- ('wait_function' , 'emit_delay_1' , 'emit_delay_2' , 'timeout' ,
96
- 'expected_signal_triggered' , 'raising' ),
97
- [
98
- (explicit_wait , 100 , 150 , 200 , True , False ),
99
- (explicit_wait , 100 , 150 , None , True , False ),
100
- (context_manager_wait , 100 , 150 , 200 , True , False ),
101
- (context_manager_wait , 100 , 150 , None , True , False ),
102
- (explicit_wait , 200 , 200 , 50 , False , False ),
103
- (explicit_wait , 100 , 200 , 150 , False , False ),
104
- (explicit_wait , 200 , 50 , 100 , False , False ),
105
- (context_manager_wait , 200 , 200 , 50 , False , False ),
106
- (context_manager_wait , 50 , 200 , 100 , False , False ),
107
- (context_manager_wait , 200 , 50 , 100 , False , False ),
108
- (context_manager_wait , 200 , 50 , 100 , False , True ),
109
- (context_manager_wait , 50 , 200 , 100 , False , True ),
110
- ]
104
+ ('delay_1' , 'delay_2' , 'timeout' , 'expected_signal_triggered' ,
105
+ 'wait_function' , 'raising' ),
106
+ build_signal_tests_variants ([
107
+ # delay1, delay2, timeout, expected_signal_triggered
108
+ (100 , 150 , 200 , True ),
109
+ (150 , 100 , 200 , True ),
110
+ (100 , 150 , None , True ),
111
+ (200 , 200 , 100 , False ),
112
+ (100 , 200 , 150 , False ),
113
+ (200 , 100 , 100 , False ),
114
+ (100 , 500 , 200 , False ),
115
+ ])
111
116
)
112
117
def test_signal_triggered_multiple (qtbot , single_shot , stop_watch , wait_function ,
113
- emit_delay_1 , emit_delay_2 , timeout ,
118
+ delay_1 , delay_2 , timeout ,
114
119
expected_signal_triggered , raising ):
115
120
"""
116
121
Testing for a signal in different conditions, ensuring we are obtaining
117
122
the expected results.
118
123
"""
119
124
signaller = Signaller ()
120
- single_shot (signaller .signal , emit_delay_1 )
121
- single_shot (signaller .signal_2 , emit_delay_2 )
125
+ single_shot (signaller .signal , delay_1 )
126
+ single_shot (signaller .signal_2 , delay_2 )
122
127
123
128
should_raise = raising and not expected_signal_triggered
124
129
@@ -133,7 +138,7 @@ def test_signal_triggered_multiple(qtbot, single_shot, stop_watch, wait_function
133
138
# ensure that either signal was triggered or timeout occurred
134
139
assert blocker .signal_triggered == expected_signal_triggered
135
140
136
- stop_watch .check (timeout , emit_delay_1 , emit_delay_2 )
141
+ stop_watch .check (timeout , delay_1 , delay_2 )
137
142
138
143
139
144
def test_explicit_emit (qtbot ):
@@ -203,7 +208,7 @@ def check(self, timeout, *delays):
203
208
delays used to trigger a signal has passed.
204
209
"""
205
210
if timeout is None :
206
- timeout = max (delays ) * 1.1 # 10 % tolerance
211
+ timeout = max (delays ) * 1.2 # 20 % tolerance
207
212
max_wait_ms = max (delays + (timeout ,))
208
213
assert time .time () - self ._start_time < (max_wait_ms / 1000.0 )
209
214
0 commit comments