def test(loop): pr, pw = os.pipe() cat_proc = loop.run_until_complete( create_subprocess_exec(cat_binary, stdin=pr, stdout=subprocess.PIPE, loop=loop)) echo_proc = loop.run_until_complete( create_subprocess_exec(echo_binary, b'-n', stdin_data, stdout=pw, loop=loop)) os.close(pr) os.close(pw) out, err = loop.run_until_complete(cat_proc.communicate()) self.assertEqual(loop.run_until_complete(cat_proc.wait()), os.EX_OK) self.assertEqual(loop.run_until_complete(echo_proc.wait()), os.EX_OK) self.assertEqual(out, stdin_data)
def test_coroutine(loop=None): proc = (yield create_subprocess_exec(echo_binary, *args_tuple, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, loop=loop)) out, err = (yield proc.communicate()) self.assertEqual(tuple(out.split()), args_tuple) self.assertEqual(proc.returncode, os.EX_OK) proc = (yield create_subprocess_exec( 'bash', '-c', 'echo foo; echo bar 1>&2;', stdout=subprocess.PIPE, stderr=subprocess.PIPE, loop=loop)) out, err = (yield proc.communicate()) self.assertEqual(out, b'foo\n') self.assertEqual(err, b'bar\n') self.assertEqual(proc.returncode, os.EX_OK) proc = (yield create_subprocess_exec( 'bash', '-c', 'echo foo; echo bar 1>&2;', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, loop=loop)) out, err = (yield proc.communicate()) self.assertEqual(out, b'foo\nbar\n') self.assertEqual(err, None) self.assertEqual(proc.returncode, os.EX_OK) coroutine_return('success')
def test_coroutine(loop=None): proc = (yield create_subprocess_exec(echo_binary, *args_tuple, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, loop=loop)) out, err = (yield proc.communicate()) self.assertEqual(tuple(out.split()), args_tuple) self.assertEqual(proc.returncode, os.EX_OK) proc = (yield create_subprocess_exec( 'bash', '-c', 'echo foo; echo bar 1>&2;', stdout=subprocess.PIPE, stderr=subprocess.PIPE, loop=loop)) out, err = (yield proc.communicate()) self.assertEqual(out, b'foo\n') self.assertEqual(err, b'bar\n') self.assertEqual(proc.returncode, os.EX_OK) proc = (yield create_subprocess_exec( 'bash', '-c', 'echo foo; echo bar 1>&2;', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, loop=loop)) out, err = (yield proc.communicate()) self.assertEqual(out, b'foo\nbar\n') self.assertEqual(err, None) self.assertEqual(proc.returncode, os.EX_OK) coroutine_return('success')
def test(loop): proc = loop.run_until_complete( create_subprocess_exec(cat_binary, stdin=subprocess.PIPE, stdout=subprocess.PIPE, loop=loop)) out, err = loop.run_until_complete(proc.communicate(input=stdin_data)) self.assertEqual(loop.run_until_complete(proc.wait()), os.EX_OK) self.assertEqual(out, stdin_data)
def test(loop): proc = loop.run_until_complete( create_subprocess_exec(cat_binary, stdin=subprocess.PIPE, stdout=subprocess.PIPE, loop=loop)) out, err = loop.run_until_complete(proc.communicate(input=stdin_data)) self.assertEqual(loop.run_until_complete(proc.wait()), os.EX_OK) self.assertEqual(out, stdin_data)
def test(loop): with open(os.devnull, 'rb', 0) as devnull: proc = loop.run_until_complete( create_subprocess_exec( echo_binary, *args_tuple, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, loop=loop)) self.assertEqual( tuple(loop.run_until_complete(proc.stdout.read()).split()), args_tuple) self.assertEqual(loop.run_until_complete(proc.wait()), os.EX_OK)
def test(loop): with open(os.devnull, 'rb', 0) as devnull: proc = loop.run_until_complete( create_subprocess_exec( echo_binary, *args_tuple, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, loop=loop)) self.assertEqual( tuple(loop.run_until_complete(proc.stdout.read()).split()), args_tuple) self.assertEqual(loop.run_until_complete(proc.wait()), os.EX_OK)
def test(loop): proc = loop.run_until_complete( create_subprocess_exec(cat_binary, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, loop=loop)) # This buffers data when necessary to avoid blocking. proc.stdin.write(stdin_data) # Any buffered data is written asynchronously after the # close method is called. proc.stdin.close() self.assertEqual(loop.run_until_complete(proc.stdout.read()), stdin_data) self.assertEqual(loop.run_until_complete(proc.wait()), os.EX_OK)
def test(loop): proc = loop.run_until_complete( create_subprocess_exec( cat_binary, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, loop=loop)) # This buffers data when necessary to avoid blocking. proc.stdin.write(stdin_data) # Any buffered data is written asynchronously after the # close method is called. proc.stdin.close() self.assertEqual( loop.run_until_complete(proc.stdout.read()), stdin_data) self.assertEqual(loop.run_until_complete(proc.wait()), os.EX_OK)