commit: b3b9acc13c432ccd1610a442d57257dfac763cc4
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 18 09:43:24 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jan 18 11:18:43 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b3b9acc1
PipeLoggerTestCase: Use async and await syntax
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/process/test_PipeLogger.py | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/lib/portage/tests/process/test_PipeLogger.py
b/lib/portage/tests/process/test_PipeLogger.py
index acc3b8af9..48e198bc5 100644
--- a/lib/portage/tests/process/test_PipeLogger.py
+++ b/lib/portage/tests/process/test_PipeLogger.py
@@ -1,4 +1,4 @@
-# Copyright 2020 Gentoo Authors
+# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
from portage import os
@@ -6,14 +6,12 @@ from portage.tests import TestCase
from portage.util._async.PipeLogger import PipeLogger
from portage.util.futures import asyncio
from portage.util.futures._asyncio.streams import _reader, _writer
-from portage.util.futures.compat_coroutine import coroutine, coroutine_return
from portage.util.futures.unix_events import _set_nonblocking
class PipeLoggerTestCase(TestCase):
- @coroutine
- def _testPipeLoggerToPipe(self, test_string, loop=None):
+ async def _testPipeLoggerToPipe(self, test_string, loop):
"""
Test PipeLogger writing to a pipe connected to a PipeReader.
This verifies that PipeLogger does not deadlock when writing
@@ -24,7 +22,7 @@ class PipeLoggerTestCase(TestCase):
input_fd, writer_pipe = os.pipe()
_set_nonblocking(writer_pipe)
writer_pipe = os.fdopen(writer_pipe, 'wb', 0)
- writer = asyncio.ensure_future(_writer(writer_pipe,
test_string.encode('ascii'), loop=loop), loop=loop)
+ writer = asyncio.ensure_future(_writer(writer_pipe,
test_string.encode('ascii')))
writer.add_done_callback(lambda writer: writer_pipe.close())
pr, pw = os.pipe()
@@ -37,22 +35,22 @@ class PipeLoggerTestCase(TestCase):
# Before starting the reader, wait here for a moment, in order
# to exercise PipeLogger's handling of EAGAIN during write.
- yield asyncio.wait([writer], timeout=0.01, loop=loop)
+ await asyncio.wait([writer], timeout=0.01)
- reader = _reader(pr, loop=loop)
- yield writer
- content = yield reader
- yield consumer.async_wait()
+ reader = _reader(pr)
+ await writer
+ content = await reader
+ await consumer.async_wait()
self.assertEqual(consumer.returncode, os.EX_OK)
- coroutine_return(content.decode('ascii', 'replace'))
+ return content.decode('ascii', 'replace')
def testPipeLogger(self):
loop = asyncio._wrap_loop()
for x in (1, 2, 5, 6, 7, 8, 2**5, 2**10, 2**12, 2**13, 2**14,
2**17, 2**17 + 1):
test_string = x * "a"
- output =
loop.run_until_complete(self._testPipeLoggerToPipe(test_string, loop=loop))
+ output =
loop.run_until_complete(self._testPipeLoggerToPipe(test_string, loop))
self.assertEqual(test_string, output,
"x = %s, len(output) = %s" % (x, len(output)))