diff options
author | Oleg Iarygin <oleg@arhadthedev.net> | 2022-10-05 14:31:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 14:31:43 (GMT) |
commit | 09aea94d291fed2f3e96558dcd6db04014c3e2fb (patch) | |
tree | 611377d3d20a127f24872f834825e556cf431043 | |
parent | 77f0249308de76401bf4f3c6a057789c92f862d1 (diff) | |
download | cpython-09aea94d291fed2f3e96558dcd6db04014c3e2fb.zip cpython-09aea94d291fed2f3e96558dcd6db04014c3e2fb.tar.gz cpython-09aea94d291fed2f3e96558dcd6db04014c3e2fb.tar.bz2 |
gh-93357: Port test cases to IsolatedAsyncioTestCase, part 2 (#97896)
This fixes the buildbots.
-rw-r--r-- | Lib/test/test_asyncio/test_streams.py | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index d1f8aef..61d5e98 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -941,34 +941,32 @@ os.close(fd) self.assertEqual(str(e), str(e2)) self.assertEqual(e.consumed, e2.consumed) +class NewStreamTests2(unittest.IsolatedAsyncioTestCase): async def test_wait_closed_on_close(self): - async with test_utils.run_test_server() as httpd: - rd, wr = self.loop.run_until_complete( - asyncio.open_connection(*httpd.address)) + with test_utils.run_test_server() as httpd: + rd, wr = await asyncio.open_connection(*httpd.address) 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') - await rd.read() + data = await rd.read() self.assertTrue(data.endswith(b'\r\n\r\nTest message')) self.assertFalse(wr.is_closing()) wr.close() self.assertTrue(wr.is_closing()) await wr.wait_closed() - def test_wait_closed_on_close_with_unread_data(self): + async def test_wait_closed_on_close_with_unread_data(self): with test_utils.run_test_server() as httpd: - rd, wr = self.loop.run_until_complete( - asyncio.open_connection(*httpd.address)) + rd, wr = await asyncio.open_connection(*httpd.address) wr.write(b'GET / HTTP/1.0\r\n\r\n') - f = rd.readline() - data = self.loop.run_until_complete(f) + data = await rd.readline() self.assertEqual(data, b'HTTP/1.0 200 OK\r\n') wr.close() - self.loop.run_until_complete(wr.wait_closed()) + await wr.wait_closed() - def test_async_writer_api(self): + async def test_async_writer_api(self): async def inner(httpd): rd, wr = await asyncio.open_connection(*httpd.address) @@ -980,15 +978,10 @@ os.close(fd) wr.close() await wr.wait_closed() - 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, []) + await inner(httpd) - def test_async_writer_api_exception_after_close(self): + async def test_async_writer_api_exception_after_close(self): async def inner(httpd): rd, wr = await asyncio.open_connection(*httpd.address) @@ -1002,24 +995,17 @@ os.close(fd) wr.write(b'data') await wr.drain() - 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, []) + await inner(httpd) async def test_eof_feed_when_closing_writer(self): # See http://bugs.python.org/issue35065 - async with test_utils.run_test_server() as httpd: + with test_utils.run_test_server() as httpd: rd, wr = await asyncio.open_connection(*httpd.address) wr.close() - f = wr.wait_closed() - self.loop.run_until_complete(f) + await wr.wait_closed() self.assertTrue(rd.at_eof()) - f = rd.read() - data = self.loop.run_until_complete(f) + data = await rd.read() self.assertEqual(data, b'') |