@@ -941,34 +941,32 @@ def test_LimitOverrunError_pickleable(self):
941
941
self .assertEqual (str (e ), str (e2 ))
942
942
self .assertEqual (e .consumed , e2 .consumed )
943
943
944
+ class NewStreamTests2 (unittest .IsolatedAsyncioTestCase ):
944
945
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 )
948
948
949
949
wr .write (b'GET / HTTP/1.0\r \n \r \n ' )
950
950
data = await rd .readline ()
951
951
self .assertEqual (data , b'HTTP/1.0 200 OK\r \n ' )
952
- await rd .read ()
952
+ data = await rd .read ()
953
953
self .assertTrue (data .endswith (b'\r \n \r \n Test message' ))
954
954
self .assertFalse (wr .is_closing ())
955
955
wr .close ()
956
956
self .assertTrue (wr .is_closing ())
957
957
await wr .wait_closed ()
958
958
959
- def test_wait_closed_on_close_with_unread_data (self ):
959
+ async def test_wait_closed_on_close_with_unread_data (self ):
960
960
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 )
963
962
964
963
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 ()
967
965
self .assertEqual (data , b'HTTP/1.0 200 OK\r \n ' )
968
966
wr .close ()
969
- self . loop . run_until_complete ( wr .wait_closed () )
967
+ await wr .wait_closed ()
970
968
971
- def test_async_writer_api (self ):
969
+ async def test_async_writer_api (self ):
972
970
async def inner (httpd ):
973
971
rd , wr = await asyncio .open_connection (* httpd .address )
974
972
@@ -980,15 +978,10 @@ async def inner(httpd):
980
978
wr .close ()
981
979
await wr .wait_closed ()
982
980
983
- messages = []
984
- self .loop .set_exception_handler (lambda loop , ctx : messages .append (ctx ))
985
-
986
981
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 )
990
983
991
- def test_async_writer_api_exception_after_close (self ):
984
+ async def test_async_writer_api_exception_after_close (self ):
992
985
async def inner (httpd ):
993
986
rd , wr = await asyncio .open_connection (* httpd .address )
994
987
@@ -1002,24 +995,17 @@ async def inner(httpd):
1002
995
wr .write (b'data' )
1003
996
await wr .drain ()
1004
997
1005
- messages = []
1006
- self .loop .set_exception_handler (lambda loop , ctx : messages .append (ctx ))
1007
-
1008
998
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 )
1012
1000
1013
1001
async def test_eof_feed_when_closing_writer (self ):
1014
1002
# 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 :
1016
1004
rd , wr = await asyncio .open_connection (* httpd .address )
1017
1005
wr .close ()
1018
- f = wr .wait_closed ()
1019
- self .loop .run_until_complete (f )
1006
+ await wr .wait_closed ()
1020
1007
self .assertTrue (rd .at_eof ())
1021
- f = rd .read ()
1022
- data = self .loop .run_until_complete (f )
1008
+ data = await rd .read ()
1023
1009
self .assertEqual (data , b'' )
1024
1010
1025
1011
0 commit comments