bpo-34666: Implement stream.awrite() and stream.aclose() (GH-9274)

This commit is contained in:
Andrew Svetlov 2018-09-13 16:53:49 -07:00 committed by GitHub
parent 413118ebf3
commit 11194c877c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 22 deletions

View file

@ -964,6 +964,28 @@ os.close(fd)
'call "stream.close()" explicitly.',
messages[0]['message'])
def test_async_writer_api(self):
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))
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(data, b'HTTP/1.0 200 OK\r\n')
f = rd.read()
data = self.loop.run_until_complete(f)
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
f = wr.aclose()
self.loop.run_until_complete(f)
self.assertEqual(messages, [])
if __name__ == '__main__':
unittest.main()