1 |
commit: 40306beadf35659ce6dbe40ffe10c677e6e13918 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Nov 16 08:52:51 2019 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Nov 16 08:54:49 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=40306bea |
7 |
|
8 |
SubprocessExecTestCase: test pipe between processes |
9 |
|
10 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
11 |
|
12 |
.../util/futures/asyncio/test_subprocess_exec.py | 36 ++++++++++++++++++++-- |
13 |
1 file changed, 34 insertions(+), 2 deletions(-) |
14 |
|
15 |
diff --git a/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py b/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py |
16 |
index 61646cb92..d7e94d132 100644 |
17 |
--- a/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py |
18 |
+++ b/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py |
19 |
@@ -1,4 +1,4 @@ |
20 |
-# Copyright 2018 Gentoo Foundation |
21 |
+# Copyright 2018-2019 Gentoo Authors |
22 |
# Distributed under the terms of the GNU General Public License v2 |
23 |
|
24 |
import os |
25 |
@@ -10,7 +10,6 @@ from portage.tests import TestCase |
26 |
from portage.util._eventloop.global_event_loop import global_event_loop |
27 |
from portage.util.futures import asyncio |
28 |
from portage.util.futures._asyncio import create_subprocess_exec |
29 |
-from portage.util.futures._asyncio.streams import _reader as reader |
30 |
from portage.util.futures.compat_coroutine import coroutine, coroutine_return |
31 |
from portage.util.futures.unix_events import DefaultEventLoopPolicy |
32 |
|
33 |
@@ -94,6 +93,39 @@ class SubprocessExecTestCase(TestCase): |
34 |
|
35 |
self._run_test(test) |
36 |
|
37 |
+ def testPipe(self): |
38 |
+ stdin_data = b'hello world' |
39 |
+ cat_binary = find_binary("cat") |
40 |
+ self.assertNotEqual(cat_binary, None) |
41 |
+ cat_binary = cat_binary.encode() |
42 |
+ |
43 |
+ echo_binary = find_binary("echo") |
44 |
+ self.assertNotEqual(echo_binary, None) |
45 |
+ echo_binary = echo_binary.encode() |
46 |
+ |
47 |
+ def test(loop): |
48 |
+ |
49 |
+ pr, pw = os.pipe() |
50 |
+ |
51 |
+ cat_proc = loop.run_until_complete(create_subprocess_exec( |
52 |
+ cat_binary, stdin=pr, stdout=subprocess.PIPE, |
53 |
+ loop=loop)) |
54 |
+ |
55 |
+ echo_proc = loop.run_until_complete(create_subprocess_exec( |
56 |
+ echo_binary, b'-n', stdin_data, stdout=pw, |
57 |
+ loop=loop)) |
58 |
+ |
59 |
+ os.close(pr) |
60 |
+ os.close(pw) |
61 |
+ |
62 |
+ out, err = loop.run_until_complete(cat_proc.communicate()) |
63 |
+ |
64 |
+ self.assertEqual(loop.run_until_complete(cat_proc.wait()), os.EX_OK) |
65 |
+ self.assertEqual(loop.run_until_complete(echo_proc.wait()), os.EX_OK) |
66 |
+ self.assertEqual(out, stdin_data) |
67 |
+ |
68 |
+ self._run_test(test) |
69 |
+ |
70 |
def testReadTransport(self): |
71 |
""" |
72 |
Test asyncio.create_subprocess_exec(stdout=subprocess.PIPE) which |