@@ -18,29 +18,28 @@ class _TestAioHTTP:
1818
1919 def test_aiohttp_basic_1 (self ):
2020
21- PAYLOAD = ' <h1>It Works!</h1>' * 10000
21+ PAYLOAD = " <h1>It Works!</h1>" * 10000
2222
2323 async def on_request (request ):
2424 return aiohttp .web .Response (text = PAYLOAD )
2525
2626 asyncio .set_event_loop (self .loop )
2727 app = aiohttp .web .Application ()
28- app .router .add_get ('/' , on_request )
28+ app .router .add_get ("/" , on_request )
2929
3030 runner = aiohttp .web .AppRunner (app )
3131 self .loop .run_until_complete (runner .setup ())
32- site = aiohttp .web .TCPSite (runner , ' 0.0.0.0' , '0' )
32+ site = aiohttp .web .TCPSite (runner , " 0.0.0.0" , "0" )
3333 self .loop .run_until_complete (site .start ())
3434 port = site ._server .sockets [0 ].getsockname ()[1 ]
3535
3636 async def test ():
3737 # Make sure we're using the correct event loop.
3838 self .assertIs (asyncio .get_event_loop (), self .loop )
3939
40- for addr in (('localhost' , port ),
41- ('127.0.0.1' , port )):
40+ for addr in (("localhost" , port ), ("127.0.0.1" , port )):
4241 async with aiohttp .ClientSession () as client :
43- async with client .get (' http://{}:{}' .format (* addr )) as r :
42+ async with client .get (" http://{}:{}" .format (* addr )) as r :
4443 self .assertEqual (r .status , 200 )
4544 result = await r .text ()
4645 self .assertEqual (result , PAYLOAD )
@@ -49,42 +48,43 @@ async def test():
4948 self .loop .run_until_complete (runner .cleanup ())
5049
5150 def test_aiohttp_graceful_shutdown (self ):
52- if self .implementation == ' asyncio' and sys .version_info >= (3 , 12 , 0 ):
51+ if self .implementation == " asyncio" and sys .version_info >= (3 , 12 , 0 ):
5352 # In Python 3.12.0, asyncio.Server.wait_closed() waits for all
5453 # existing connections to complete, before aiohttp sends
5554 # on_shutdown signals.
5655 # https://github.com/aio-libs/aiohttp/issues/7675#issuecomment-1752143748
5756 # https://github.com/python/cpython/pull/98582
58- raise unittest .SkipTest (' bug in aiohttp: #7675' )
57+ raise unittest .SkipTest (" bug in aiohttp: #7675" )
5958
6059 async def websocket_handler (request ):
6160 ws = aiohttp .web .WebSocketResponse ()
6261 await ws .prepare (request )
63- request .app [' websockets' ].add (ws )
62+ request .app [" websockets" ].add (ws )
6463 try :
6564 async for msg in ws :
6665 await ws .send_str (msg .data )
6766 finally :
68- request .app [' websockets' ].discard (ws )
67+ request .app [" websockets" ].discard (ws )
6968 return ws
7069
7170 async def on_shutdown (app ):
72- for ws in set (app [' websockets' ]):
71+ for ws in set (app [" websockets" ]):
7372 await ws .close (
7473 code = aiohttp .WSCloseCode .GOING_AWAY ,
75- message = 'Server shutdown' )
74+ message = "Server shutdown" ,
75+ )
7676
7777 asyncio .set_event_loop (self .loop )
7878 app = aiohttp .web .Application ()
79- app .router .add_get ('/' , websocket_handler )
79+ app .router .add_get ("/" , websocket_handler )
8080 app .on_shutdown .append (on_shutdown )
81- app [' websockets' ] = weakref .WeakSet ()
81+ app [" websockets" ] = weakref .WeakSet ()
8282
8383 runner = aiohttp .web .AppRunner (app )
8484 self .loop .run_until_complete (runner .setup ())
8585 site = aiohttp .web .TCPSite (
8686 runner ,
87- ' 0.0.0.0' ,
87+ " 0.0.0.0" ,
8888 0 ,
8989 # https://github.com/aio-libs/aiohttp/pull/7188
9090 shutdown_timeout = 0.1 ,
@@ -95,7 +95,8 @@ async def on_shutdown(app):
9595 async def client ():
9696 async with aiohttp .ClientSession () as client :
9797 async with client .ws_connect (
98- 'http://127.0.0.1:{}' .format (port )) as ws :
98+ "http://127.0.0.1:{}" .format (port )
99+ ) as ws :
99100 await ws .send_str ("hello" )
100101 async for msg in ws :
101102 assert msg .data == "hello"
0 commit comments