1515
1616from . import utils as test_utils
1717
18+
1819class MySubprocessProtocol (asyncio .SubprocessProtocol ):
1920 def __init__ (self , loop ):
2021 self .state = 'INITIAL'
@@ -61,16 +62,20 @@ def check_terminated(returncode):
6162 else :
6263 assert - signal .SIGTERM == returncode
6364
65+
6466def check_killed (returncode ):
6567 if sys .platform == 'win32' :
6668 assert isinstance (returncode , int )
6769 # expect 1 but sometimes get 0
6870 else :
6971 assert - signal .SIGKILL == returncode
7072
73+
7174@pytest .mark .trio
7275async def test_subprocess_exec (loop ):
7376 await run_subprocess_exec (loop )
77+
78+
7479@aio_as_trio
7580async def run_subprocess_exec (loop ):
7681 prog = os .path .join (os .path .dirname (__file__ ), 'scripts' , 'echo.py' )
@@ -92,9 +97,12 @@ async def run_subprocess_exec(loop):
9297 check_killed (proto .returncode )
9398 assert b'Python The Winner' == proto .data [1 ]
9499
100+
95101@pytest .mark .trio
96102async def test_subprocess_interactive (loop ):
97103 await run_subprocess_interactive (loop )
104+
105+
98106@aio_as_trio
99107async def run_subprocess_interactive (loop ):
100108 prog = os .path .join (os .path .dirname (__file__ ), 'scripts' , 'echo.py' )
@@ -122,14 +130,15 @@ async def run_subprocess_interactive(loop):
122130 await proto .completed
123131 check_killed (proto .returncode )
124132
133+
125134@pytest .mark .trio
126135async def test_subprocess_shell (loop ):
127136 await run_subprocess_shell (loop )
137+
138+
128139@aio_as_trio
129140async def run_subprocess_shell (loop ):
130- connect = loop .subprocess_shell (
131- functools .partial (MySubprocessProtocol , loop ), 'echo Python'
132- )
141+ connect = loop .subprocess_shell (functools .partial (MySubprocessProtocol , loop ), 'echo Python' )
133142 transp , proto = await connect
134143 assert isinstance (proto , MySubprocessProtocol )
135144 await proto .connected
@@ -142,9 +151,12 @@ async def run_subprocess_shell(loop):
142151 assert proto .data [2 ] == b''
143152 transp .close ()
144153
154+
145155@pytest .mark .trio
146156async def test_subprocess_exitcode (loop ):
147157 await run_subprocess_exitcode (loop )
158+
159+
148160@aio_as_trio
149161async def run_subprocess_exitcode (loop ):
150162 connect = loop .subprocess_shell (
@@ -160,9 +172,12 @@ async def run_subprocess_exitcode(loop):
160172 assert 7 == proto .returncode
161173 transp .close ()
162174
175+
163176@pytest .mark .trio
164177async def test_subprocess_close_after_finish (loop ):
165178 await run_subprocess_close_after_finish (loop )
179+
180+
166181@aio_as_trio
167182async def run_subprocess_close_after_finish (loop ):
168183 connect = loop .subprocess_shell (
@@ -181,9 +196,12 @@ async def run_subprocess_close_after_finish(loop):
181196 assert 7 == proto .returncode
182197 assert transp .close () is None
183198
199+
184200@pytest .mark .trio
185201async def test_subprocess_kill (loop ):
186202 await run_subprocess_kill (loop )
203+
204+
187205@aio_as_trio
188206async def run_subprocess_kill (loop ):
189207 prog = os .path .join (os .path .dirname (__file__ ), 'scripts' , 'echo.py' )
@@ -200,9 +218,12 @@ async def run_subprocess_kill(loop):
200218 check_killed (proto .returncode )
201219 transp .close ()
202220
221+
203222@pytest .mark .trio
204223async def test_subprocess_terminate (loop ):
205224 await run_subprocess_terminate (loop )
225+
226+
206227@aio_as_trio
207228async def run_subprocess_terminate (loop ):
208229 prog = os .path .join (os .path .dirname (__file__ ), 'scripts' , 'echo.py' )
@@ -219,10 +240,13 @@ async def run_subprocess_terminate(loop):
219240 check_terminated (proto .returncode )
220241 transp .close ()
221242
243+
222244@unittest .skipIf (sys .platform == 'win32' , "Don't have SIGHUP" )
223245@pytest .mark .trio
224246async def test_subprocess_send_signal (loop ):
225247 await run_subprocess_send_signal (loop )
248+
249+
226250@aio_as_trio
227251async def run_subprocess_send_signal (loop ):
228252 # bpo-31034: Make sure that we get the default signal handler (killing
@@ -246,9 +270,12 @@ async def run_subprocess_send_signal(loop):
246270 finally :
247271 signal .signal (signal .SIGHUP , old_handler )
248272
273+
249274@pytest .mark .trio
250275async def test_subprocess_stderr (loop ):
251276 await run_subprocess_stderr (loop )
277+
278+
252279@aio_as_trio
253280async def run_subprocess_stderr (loop ):
254281 prog = os .path .join (os .path .dirname (__file__ ), 'scripts' , 'echo2.py' )
@@ -270,9 +297,12 @@ async def run_subprocess_stderr(loop):
270297 assert proto .data [2 ].startswith (b'ERR:test' ), proto .data [2 ]
271298 assert 0 == proto .returncode
272299
300+
273301@pytest .mark .trio
274302async def test_subprocess_stderr_redirect_to_stdout (loop ):
275303 await run_subprocess_stderr_redirect_to_stdout (loop )
304+
305+
276306@aio_as_trio
277307async def run_subprocess_stderr_redirect_to_stdout (loop ):
278308 prog = os .path .join (os .path .dirname (__file__ ), 'scripts' , 'echo2.py' )
@@ -299,9 +329,12 @@ async def run_subprocess_stderr_redirect_to_stdout(loop):
299329 transp .close ()
300330 assert 0 == proto .returncode
301331
332+
302333@pytest .mark .trio
303334async def test_subprocess_close_client_stream (loop ):
304335 await run_subprocess_close_client_stream (loop )
336+
337+
305338@aio_as_trio
306339async def run_subprocess_close_client_stream (loop ):
307340 prog = os .path .join (os .path .dirname (__file__ ), 'scripts' , 'echo3.py' )
@@ -336,9 +369,12 @@ async def run_subprocess_close_client_stream(loop):
336369 await proto .completed
337370 check_killed (proto .returncode )
338371
372+
339373@pytest .mark .trio
340374async def test_subprocess_wait_no_same_group (loop ):
341375 await run_subprocess_wait_no_same_group (loop )
376+
377+
342378@aio_as_trio
343379async def run_subprocess_wait_no_same_group (loop ):
344380 # start the new process in a new session
@@ -355,6 +391,7 @@ async def run_subprocess_wait_no_same_group(loop):
355391 await proto .completed
356392 assert 7 == proto .returncode
357393
394+
358395@pytest .mark .trio
359396async def test_subprocess_exec_invalid_args (loop ):
360397 @aio_as_trio
@@ -368,6 +405,7 @@ async def connect(**kwds):
368405 with pytest .raises (ValueError ):
369406 await connect (shell = True )
370407
408+
371409@pytest .mark .trio
372410async def test_subprocess_shell_invalid_args (loop ):
373411 @aio_as_trio
@@ -384,5 +422,3 @@ async def connect(cmd=None, **kwds):
384422 await connect (bufsize = 4096 )
385423 with pytest .raises (ValueError ):
386424 await connect (shell = False )
387-
388-
0 commit comments