summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-12-04 23:04:26 +0100
committerVictor Stinner <victor.stinner@gmail.com>2014-12-04 23:04:26 +0100
commitf814e5c11ce268017f448db01b51bc627d369fe3 (patch)
tree018d30b45aaba1dd863819cd2a3498e47ee2a451 /tests
parentf007f8551768f323585076e81851a83f4a60036b (diff)
downloadtrollius-f814e5c11ce268017f448db01b51bc627d369fe3.tar.gz
Python issue #22685: Fix test_pause_reading() of test_subprocess
* mock also resume_reading() * ensure that resume_reading() is called
Diffstat (limited to 'tests')
-rw-r--r--tests/test_subprocess.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py
index d0ab230..9060b9d 100644
--- a/tests/test_subprocess.py
+++ b/tests/test_subprocess.py
@@ -163,13 +163,14 @@ class SubprocessMixin:
self.loop.run_until_complete(proc.wait())
def test_pause_reading(self):
+ limit = 10
+ size = (limit * 2 + 1)
+
@asyncio.coroutine
def test_pause_reading():
- limit = 100
-
code = '\n'.join((
'import sys',
- 'sys.stdout.write("x" * %s)' % (limit * 2 + 1),
+ 'sys.stdout.write("x" * %s)' % size,
'sys.stdout.flush()',
))
proc = yield from asyncio.create_subprocess_exec(
@@ -180,18 +181,22 @@ class SubprocessMixin:
loop=self.loop)
stdout_transport = proc._transport.get_pipe_transport(1)
stdout_transport.pause_reading = mock.Mock()
+ stdout_transport.resume_reading = mock.Mock()
- yield from proc.wait()
+ stdout, stderr = yield from proc.communicate()
# The child process produced more than limit bytes of output,
# the stream reader transport should pause the protocol to not
# allocate too much memory.
- return stdout_transport.pause_reading.called
+ return (stdout, stdout_transport)
# Issue #22685: Ensure that the stream reader pauses the protocol
# when the child process produces too much data
- called = self.loop.run_until_complete(test_pause_reading())
- self.assertTrue(called)
+ stdout, transport = self.loop.run_until_complete(test_pause_reading())
+
+ self.assertEqual(stdout, b'x' * size)
+ self.assertTrue(transport.pause_reading.called)
+ self.assertTrue(transport.resume_reading.called)
if sys.platform != 'win32':