Skip to content

Commit 09aea94

Browse files
authored
pythongh-93357: Port test cases to IsolatedAsyncioTestCase, part 2 (python#97896)
This fixes the buildbots.
1 parent 77f0249 commit 09aea94

File tree

1 file changed

+15
-29
lines changed

1 file changed

+15
-29
lines changed

Lib/test/test_asyncio/test_streams.py

+15-29
Original file line numberDiff line numberDiff line change
@@ -941,34 +941,32 @@ def test_LimitOverrunError_pickleable(self):
941941
self.assertEqual(str(e), str(e2))
942942
self.assertEqual(e.consumed, e2.consumed)
943943

944+
class NewStreamTests2(unittest.IsolatedAsyncioTestCase):
944945
async def test_wait_closed_on_close(self):
945-
async with test_utils.run_test_server() as httpd:
946-
rd, wr = self.loop.run_until_complete(
947-
asyncio.open_connection(*httpd.address))
946+
with test_utils.run_test_server() as httpd:
947+
rd, wr = await asyncio.open_connection(*httpd.address)
948948

949949
wr.write(b'GET / HTTP/1.0\r\n\r\n')
950950
data = await rd.readline()
951951
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
952-
await rd.read()
952+
data = await rd.read()
953953
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
954954
self.assertFalse(wr.is_closing())
955955
wr.close()
956956
self.assertTrue(wr.is_closing())
957957
await wr.wait_closed()
958958

959-
def test_wait_closed_on_close_with_unread_data(self):
959+
async def test_wait_closed_on_close_with_unread_data(self):
960960
with test_utils.run_test_server() as httpd:
961-
rd, wr = self.loop.run_until_complete(
962-
asyncio.open_connection(*httpd.address))
961+
rd, wr = await asyncio.open_connection(*httpd.address)
963962

964963
wr.write(b'GET / HTTP/1.0\r\n\r\n')
965-
f = rd.readline()
966-
data = self.loop.run_until_complete(f)
964+
data = await rd.readline()
967965
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
968966
wr.close()
969-
self.loop.run_until_complete(wr.wait_closed())
967+
await wr.wait_closed()
970968

971-
def test_async_writer_api(self):
969+
async def test_async_writer_api(self):
972970
async def inner(httpd):
973971
rd, wr = await asyncio.open_connection(*httpd.address)
974972

@@ -980,15 +978,10 @@ async def inner(httpd):
980978
wr.close()
981979
await wr.wait_closed()
982980

983-
messages = []
984-
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
985-
986981
with test_utils.run_test_server() as httpd:
987-
self.loop.run_until_complete(inner(httpd))
988-
989-
self.assertEqual(messages, [])
982+
await inner(httpd)
990983

991-
def test_async_writer_api_exception_after_close(self):
984+
async def test_async_writer_api_exception_after_close(self):
992985
async def inner(httpd):
993986
rd, wr = await asyncio.open_connection(*httpd.address)
994987

@@ -1002,24 +995,17 @@ async def inner(httpd):
1002995
wr.write(b'data')
1003996
await wr.drain()
1004997

1005-
messages = []
1006-
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
1007-
1008998
with test_utils.run_test_server() as httpd:
1009-
self.loop.run_until_complete(inner(httpd))
1010-
1011-
self.assertEqual(messages, [])
999+
await inner(httpd)
10121000

10131001
async def test_eof_feed_when_closing_writer(self):
10141002
# See http://bugs.python.org/issue35065
1015-
async with test_utils.run_test_server() as httpd:
1003+
with test_utils.run_test_server() as httpd:
10161004
rd, wr = await asyncio.open_connection(*httpd.address)
10171005
wr.close()
1018-
f = wr.wait_closed()
1019-
self.loop.run_until_complete(f)
1006+
await wr.wait_closed()
10201007
self.assertTrue(rd.at_eof())
1021-
f = rd.read()
1022-
data = self.loop.run_until_complete(f)
1008+
data = await rd.read()
10231009
self.assertEqual(data, b'')
10241010

10251011

0 commit comments

Comments
 (0)