summaryrefslogtreecommitdiff
path: root/Lib/test/test_asyncio/test_streams.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2017-12-09 00:23:48 +0200
committerGitHub <noreply@github.com>2017-12-09 00:23:48 +0200
commit5f841b553814969220b096a2b4f959b7f6fcbaf6 (patch)
treeb48ea916d9585efa9bf7ff370b50c4e2dfb30247 /Lib/test/test_asyncio/test_streams.py
parentede157331b4f9e550334900b3b4de1c8590688de (diff)
downloadcpython-git-5f841b553814969220b096a2b4f959b7f6fcbaf6.tar.gz
bpo-32193: Convert asyncio to async/await usage (#4753)
* Convert asyncio/tasks.py to async/await * Convert asyncio/queues.py to async/await * Convert asyncio/test_utils.py to async/await * Convert asyncio/base_subprocess.py to async/await * Convert asyncio/subprocess.py to async/await * Convert asyncio/streams.py to async/await * Fix comments * Convert asyncio/locks.py to async/await * Convert asyncio.sleep to async def * Add a comment * Add missing news * Convert stubs from AbstrctEventLoop to async functions * Convert subprocess_shell/subprocess_exec * Convert connect_read_pipe/connect_write_pip to async/await syntax * Convert create_datagram_endpoint * Convert create_unix_server/create_unix_connection * Get rid of old style coroutines in unix_events.py * Convert selector_events.py to async/await * Convert wait_closed and create_connection * Drop redundant line * Convert base_events.py * Code cleanup * Drop redundant comments * Fix indentation * Add explicit tests for compatibility between old and new coroutines * Convert windows event loop to use async/await * Fix double awaiting of async function * Convert asyncio/locks.py * Improve docstring * Convert tests to async/await * Convert more tests * Convert more tests * Convert more tests * Convert tests * Improve test
Diffstat (limited to 'Lib/test/test_asyncio/test_streams.py')
-rw-r--r--Lib/test/test_asyncio/test_streams.py35
1 files changed, 15 insertions, 20 deletions
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index a1e5bd7fab..2f4e6d23bf 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -571,11 +571,10 @@ class StreamReaderTests(test_utils.TestCase):
self.server = None
self.loop = loop
- @asyncio.coroutine
- def handle_client(self, client_reader, client_writer):
- data = yield from client_reader.readline()
+ async def handle_client(self, client_reader, client_writer):
+ data = await client_reader.readline()
client_writer.write(data)
- yield from client_writer.drain()
+ await client_writer.drain()
client_writer.close()
def start(self):
@@ -608,14 +607,13 @@ class StreamReaderTests(test_utils.TestCase):
self.loop.run_until_complete(self.server.wait_closed())
self.server = None
- @asyncio.coroutine
- def client(addr):
- reader, writer = yield from asyncio.open_connection(
+ async def client(addr):
+ reader, writer = await asyncio.open_connection(
*addr, loop=self.loop)
# send a line
writer.write(b"hello world!\n")
# read it back
- msgback = yield from reader.readline()
+ msgback = await reader.readline()
writer.close()
return msgback
@@ -645,11 +643,10 @@ class StreamReaderTests(test_utils.TestCase):
self.loop = loop
self.path = path
- @asyncio.coroutine
- def handle_client(self, client_reader, client_writer):
- data = yield from client_reader.readline()
+ async def handle_client(self, client_reader, client_writer):
+ data = await client_reader.readline()
client_writer.write(data)
- yield from client_writer.drain()
+ await client_writer.drain()
client_writer.close()
def start(self):
@@ -674,14 +671,13 @@ class StreamReaderTests(test_utils.TestCase):
self.loop.run_until_complete(self.server.wait_closed())
self.server = None
- @asyncio.coroutine
- def client(path):
- reader, writer = yield from asyncio.open_unix_connection(
+ async def client(path):
+ reader, writer = await asyncio.open_unix_connection(
path, loop=self.loop)
# send a line
writer.write(b"hello world!\n")
# read it back
- msgback = yield from reader.readline()
+ msgback = await reader.readline()
writer.close()
return msgback
@@ -782,14 +778,13 @@ os.close(fd)
clt, _ = sock.accept()
clt.close()
- @asyncio.coroutine
- def client(host, port):
- reader, writer = yield from asyncio.open_connection(
+ async def client(host, port):
+ reader, writer = await asyncio.open_connection(
host, port, loop=self.loop)
while True:
writer.write(b"foo\n")
- yield from writer.drain()
+ await writer.drain()
# Start the server thread and wait for it to be listening.
thread = threading.Thread(target=server)