summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorsbstp <sbstp@users.noreply.github.com>2019-05-27 23:51:19 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-05-27 23:51:19 (GMT)
commitf0d4c64019ecf8a5f362aa5a478786241613e5c3 (patch)
treeba78feaf8749f5ddc5ad66fb369aba3a90d1567d /Lib/test/test_asyncio
parenta3568417c49f36860393075b21c93996a5f6799b (diff)
downloadcpython-f0d4c64019ecf8a5f362aa5a478786241613e5c3.zip
cpython-f0d4c64019ecf8a5f362aa5a478786241613e5c3.tar.gz
cpython-f0d4c64019ecf8a5f362aa5a478786241613e5c3.tar.bz2
bpo-36686: Improve the documentation of the std* params in loop.subprocess_exec (GH-13586)
https://bugs.python.org/issue36686
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index 551974a..f1ab039 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -335,6 +335,63 @@ class SubprocessMixin:
self.assertEqual(output.rstrip(), b'0')
self.assertEqual(exitcode, 0)
+ def test_devnull_input(self):
+
+ async def empty_input():
+ code = 'import sys; data = sys.stdin.read(); print(len(data))'
+ proc = await asyncio.create_subprocess_exec(
+ sys.executable, '-c', code,
+ stdin=asyncio.subprocess.DEVNULL,
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE,
+ close_fds=False,
+ loop=self.loop)
+ stdout, stderr = await proc.communicate()
+ exitcode = await proc.wait()
+ return (stdout, exitcode)
+
+ output, exitcode = self.loop.run_until_complete(empty_input())
+ self.assertEqual(output.rstrip(), b'0')
+ self.assertEqual(exitcode, 0)
+
+ def test_devnull_output(self):
+
+ async def empty_output():
+ code = 'import sys; data = sys.stdin.read(); print(len(data))'
+ proc = await asyncio.create_subprocess_exec(
+ sys.executable, '-c', code,
+ stdin=asyncio.subprocess.PIPE,
+ stdout=asyncio.subprocess.DEVNULL,
+ stderr=asyncio.subprocess.PIPE,
+ close_fds=False,
+ loop=self.loop)
+ stdout, stderr = await proc.communicate(b"abc")
+ exitcode = await proc.wait()
+ return (stdout, exitcode)
+
+ output, exitcode = self.loop.run_until_complete(empty_output())
+ self.assertEqual(output, None)
+ self.assertEqual(exitcode, 0)
+
+ def test_devnull_error(self):
+
+ async def empty_error():
+ code = 'import sys; data = sys.stdin.read(); print(len(data))'
+ proc = await asyncio.create_subprocess_exec(
+ sys.executable, '-c', code,
+ stdin=asyncio.subprocess.PIPE,
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.DEVNULL,
+ close_fds=False,
+ loop=self.loop)
+ stdout, stderr = await proc.communicate(b"abc")
+ exitcode = await proc.wait()
+ return (stderr, exitcode)
+
+ output, exitcode = self.loop.run_until_complete(empty_error())
+ self.assertEqual(output, None)
+ self.assertEqual(exitcode, 0)
+
def test_cancel_process_wait(self):
# Issue #23140: cancel Process.wait()
@@ -531,6 +588,39 @@ class SubprocessMixin:
with self.assertWarns(DeprecationWarning):
subprocess.Process(transp, proto, loop=self.loop)
+ def test_create_subprocess_exec_text_mode_fails(self):
+ async def execute():
+ with self.assertRaises(ValueError):
+ await subprocess.create_subprocess_exec(sys.executable,
+ text=True)
+
+ with self.assertRaises(ValueError):
+ await subprocess.create_subprocess_exec(sys.executable,
+ encoding="utf-8")
+
+ with self.assertRaises(ValueError):
+ await subprocess.create_subprocess_exec(sys.executable,
+ errors="strict")
+
+ self.loop.run_until_complete(execute())
+
+ def test_create_subprocess_shell_text_mode_fails(self):
+
+ async def execute():
+ with self.assertRaises(ValueError):
+ await subprocess.create_subprocess_shell(sys.executable,
+ text=True)
+
+ with self.assertRaises(ValueError):
+ await subprocess.create_subprocess_shell(sys.executable,
+ encoding="utf-8")
+
+ with self.assertRaises(ValueError):
+ await subprocess.create_subprocess_shell(sys.executable,
+ errors="strict")
+
+ self.loop.run_until_complete(execute())
+
if sys.platform != 'win32':
# Unix