aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_asyncio/test_streams.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2019-05-09 15:14:58 -0400
committerGitHub <noreply@github.com>2019-05-09 15:14:58 -0400
commita076e4f5e42b85664693191d04cfb33e2f9acfa5 (patch)
tree3b70de541e9e742bde047631a2db60078ad18e35 /Lib/test/test_asyncio/test_streams.py
parent3b2f9ab31db81405650325920465378532ab2d78 (diff)
downloadcpython-a076e4f5e42b85664693191d04cfb33e2f9acfa5.tar.gz
cpython-a076e4f5e42b85664693191d04cfb33e2f9acfa5.zip
bpo-36802: Drop awrite()/aclose(), support await write() and await close() instead (#13099)
Diffstat (limited to 'Lib/test/test_asyncio/test_streams.py')
-rw-r--r--Lib/test/test_asyncio/test_streams.py42
1 files changed, 30 insertions, 12 deletions
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index 905141ca89c..bf93f30e1aa 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -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()