bpo-36802: Drop awrite()/aclose(), support await write() and await close() instead (#13099)

This commit is contained in:
Andrew Svetlov 2019-05-09 15:14:58 -04:00 committed by GitHub
parent 3b2f9ab31d
commit a076e4f5e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 118 additions and 51 deletions

View file

@ -1035,24 +1035,42 @@ os.close(fd)
messages[0]['message'])
def test_async_writer_api(self):
async def inner(httpd):
rd, wr = await asyncio.open_connection(*httpd.address)
await wr.write(b'GET / HTTP/1.0\r\n\r\n')
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
data = await rd.read()
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
await wr.close()
messages = []
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
with test_utils.run_test_server() as httpd:
rd, wr = self.loop.run_until_complete(
asyncio.open_connection(*httpd.address,
loop=self.loop))
self.loop.run_until_complete(inner(httpd))
f = wr.awrite(b'GET / HTTP/1.0\r\n\r\n')
self.loop.run_until_complete(f)
f = rd.readline()
data = self.loop.run_until_complete(f)
self.assertEqual(messages, [])
def test_async_writer_api(self):
async def inner(httpd):
rd, wr = await asyncio.open_connection(*httpd.address)
await wr.write(b'GET / HTTP/1.0\r\n\r\n')
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
f = rd.read()
data = self.loop.run_until_complete(f)
data = await rd.read()
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
f = wr.aclose()
self.loop.run_until_complete(f)
wr.close()
with self.assertRaises(ConnectionResetError):
await wr.write(b'data')
messages = []
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
with test_utils.run_test_server() as httpd:
self.loop.run_until_complete(inner(httpd))
self.assertEqual(messages, [])
@ -1066,7 +1084,7 @@ os.close(fd)
asyncio.open_connection(*httpd.address,
loop=self.loop))
f = wr.aclose()
f = wr.close()
self.loop.run_until_complete(f)
assert rd.at_eof()
f = rd.read()