@@ -342,6 +342,10 @@ class _AsyncioTests:
342
342
'data = sys.stdin.buffer.read()' ,
343
343
'sys.stdout.buffer.write(data)' ))]
344
344
345
+ PROGRAM_ERROR = [
346
+ sys .executable , '-c' , '1/0'
347
+ ]
348
+
345
349
def test_stdin_not_inheritable (self ):
346
350
# asyncio issue #209: stdin must not be inheritable, otherwise
347
351
# the Process.communicate() hangs
@@ -363,7 +367,7 @@ def len_message(message):
363
367
self .assertEqual (output .rstrip (), b'3' )
364
368
self .assertEqual (exitcode , 0 )
365
369
366
- def test_stdin_stdout (self ):
370
+ def test_stdin_stdout_pipe (self ):
367
371
args = self .PROGRAM_CAT
368
372
369
373
@asyncio .coroutine
@@ -390,6 +394,57 @@ def run(data):
390
394
self .assertEqual (exitcode , 0 )
391
395
self .assertEqual (stdout , b'some data' )
392
396
397
+ def test_stdin_stdout_file (self ):
398
+ args = self .PROGRAM_CAT
399
+
400
+ @asyncio .coroutine
401
+ def run (data , stderr ):
402
+ proc = yield from asyncio .create_subprocess_exec (
403
+ * args ,
404
+ stdin = subprocess .PIPE ,
405
+ stderr = stdout ,
406
+ loop = self .loop )
407
+
408
+ # feed data
409
+ proc .stdin .write (data )
410
+ yield from proc .stdin .drain ()
411
+ proc .stdin .close ()
412
+
413
+ exitcode = yield from proc .wait ()
414
+ return exitcode
415
+
416
+ with tempfile .TemporaryFile ('w+b' ) as new_stdout :
417
+ task = run (b'some data' , new_stdout )
418
+ task = asyncio .wait_for (task , 60.0 , loop = self .loop )
419
+ exitcode = self .loop .run_until_complete (task )
420
+ self .assertEqual (exitcode , 0 )
421
+
422
+ new_stdout .seek (0 )
423
+ self .assertEqual (new_stdout .read (), b'some data' )
424
+
425
+ def test_stdin_stderr_file (self ):
426
+ args = self .PROGRAM_ERROR
427
+
428
+ @asyncio .coroutine
429
+ def run (stderr ):
430
+ proc = yield from asyncio .create_subprocess_exec (
431
+ * args ,
432
+ stdin = subprocess .PIPE ,
433
+ stderr = stderr ,
434
+ loop = self .loop )
435
+
436
+ exitcode = yield from proc .wait ()
437
+ return exitcode
438
+
439
+ with tempfile .TemporaryFile ('w+b' ) as new_stderr :
440
+ task = run (new_stderr )
441
+ task = asyncio .wait_for (task , 60.0 , loop = self .loop )
442
+ exitcode = self .loop .run_until_complete (task )
443
+ self .assertEqual (exitcode , 1 )
444
+
445
+ new_stderr .seek (0 )
446
+ self .assertIn (b'ZeroDivisionError' , new_stderr .read ())
447
+
393
448
def test_communicate (self ):
394
449
args = self .PROGRAM_CAT
395
450
0 commit comments