@@ -47,11 +47,7 @@ async def _wait_for_event_with_condition(
4747):
4848 pyevent = asyncio .Event ()
4949 event_handler = get_launch_event_handler (execute_process_action , pyevent )
50- cond_value = False
51- try :
52- cond_value = condition ()
53- except AssertionError :
54- pass
50+ cond_value = condition ()
5551 with register_event_handler (launch_context , event_handler ):
5652 start = time .time ()
5753 now = start
@@ -61,15 +57,9 @@ async def _wait_for_event_with_condition(
6157 except asyncio .TimeoutError :
6258 break
6359 pyevent .clear ()
64- try :
65- cond_value = condition ()
66- except AssertionError :
67- pass
60+ cond_value = condition ()
6861 now = time .time ()
69- # Call condition() again, if before it returned False.
70- # If assertions were being used and the condition is still not satisfied it should raise here,
71- # pytest renders assertion errors nicely.
72- return condition () if not cond_value else cond_value
62+ return cond_value
7363
7464
7565def _wait_for_event_sync (
@@ -86,26 +76,16 @@ def _wait_for_event_with_condition_sync(
8676):
8777 pyevent = threading .Event ()
8878 event_handler = get_launch_event_handler (execute_process_action , pyevent )
89- cond_value = False
90- try :
91- cond_value = condition ()
92- except AssertionError :
93- pass # Allow asserts in the condition closures
79+ cond_value = condition ()
9480 with register_event_handler (launch_context , event_handler ):
9581 start = time .time ()
9682 now = start
9783 while not cond_value and (timeout is None or now < start + timeout ):
9884 pyevent .wait (start - now + timeout )
9985 pyevent .clear ()
100- try :
101- cond_value = condition ()
102- except AssertionError :
103- pass
86+ cond_value = condition ()
10487 now = time .time ()
105- # Call condition() again, if before it returned False.
106- # If assertions were being used and the condition is still not satisfied it should raise here,
107- # pytest renders assertion errors nicely.
108- return condition () if not cond_value else cond_value
88+ return cond_value
10989
11090
11191def _get_stdout_event_handler (action , pyevent ):
@@ -124,6 +104,25 @@ async def wait_for_output(
124104 timeout )
125105
126106
107+ async def assert_output (
108+ launch_context , execute_process_action , validate_output , timeout = None
109+ ):
110+ def condition ():
111+ try :
112+ validate_output (execute_process_action .get_stdout ())
113+ except AssertionError :
114+ return False
115+ return True
116+ cond_value = await _wait_for_event_with_condition (
117+ launch_context ,
118+ execute_process_action ,
119+ _get_stdout_event_handler ,
120+ condition ,
121+ timeout )
122+ if not cond_value :
123+ validate_output (execute_process_action .get_stdout ())
124+
125+
127126def wait_for_output_sync (
128127 launch_context , execute_process_action , validate_output , timeout = None
129128):
@@ -135,6 +134,25 @@ def wait_for_output_sync(
135134 timeout )
136135
137136
137+ def assert_output_sync (
138+ launch_context , execute_process_action , validate_output , timeout = None
139+ ):
140+ def condition ():
141+ try :
142+ validate_output (execute_process_action .get_stdout ())
143+ except AssertionError :
144+ return False
145+ return True
146+ cond_value = _wait_for_event_with_condition_sync (
147+ launch_context ,
148+ execute_process_action ,
149+ _get_stdout_event_handler ,
150+ condition ,
151+ timeout )
152+ if not cond_value :
153+ validate_output (execute_process_action .get_stdout ())
154+
155+
138156def _get_stderr_event_handler (action , pyevent ):
139157 return event_handlers .OnProcessIO (
140158 target_action = action , on_stderr = lambda _1 : pyevent .set ())
@@ -151,6 +169,25 @@ async def wait_for_stderr(
151169 timeout )
152170
153171
172+ async def assert_stderr (
173+ launch_context , execute_process_action , validate_output , timeout = None
174+ ):
175+ def condition ():
176+ try :
177+ validate_output (execute_process_action .get_stderr ())
178+ except AssertionError :
179+ return False
180+ return True
181+ cond_value = await _wait_for_event_with_condition (
182+ launch_context ,
183+ execute_process_action ,
184+ _get_stderr_event_handler ,
185+ condition ,
186+ timeout )
187+ if not cond_value :
188+ validate_output (execute_process_action .get_stderr ())
189+
190+
154191def wait_for_stderr_sync (
155192 launch_context , execute_process_action , validate_output , timeout = None
156193):
@@ -162,6 +199,25 @@ def wait_for_stderr_sync(
162199 timeout )
163200
164201
202+ def assert_stderr_sync (
203+ launch_context , execute_process_action , validate_output , timeout = None
204+ ):
205+ def condition ():
206+ try :
207+ validate_output (execute_process_action .get_stderr ())
208+ except AssertionError :
209+ return False
210+ return True
211+ cond_value = _wait_for_event_with_condition_sync (
212+ launch_context ,
213+ execute_process_action ,
214+ _get_stderr_event_handler ,
215+ condition ,
216+ timeout )
217+ if not cond_value :
218+ validate_output (execute_process_action .get_stderr ())
219+
220+
165221def _get_on_process_start_event_handler (execute_process_action , pyevent ):
166222 return event_handlers .OnProcessStart (
167223 target_action = execute_process_action , on_start = lambda _1 , _2 : pyevent .set ())
0 commit comments