@@ -318,19 +318,7 @@ async def test():
318318
319319 self .loop .run_until_complete (test ())
320320
321- def test_create_connection_1 (self ):
322- CNT = 0
323- TOTAL_CNT = 100
324-
325- def server (sock ):
326- data = sock .recv_all (4 )
327- self .assertEqual (data , b'AAAA' )
328- sock .send (b'OK' )
329-
330- data = sock .recv_all (4 )
331- self .assertEqual (data , b'BBBB' )
332- sock .send (b'SPAM' )
333-
321+ def test_create_connection_open_con_addr (self ):
334322 async def client (addr ):
335323 reader , writer = await asyncio .open_connection (
336324 * addr ,
@@ -352,12 +340,12 @@ async def client(addr):
352340 self .assertTrue (
353341 sock .getsockopt (socket .IPPROTO_TCP , socket .TCP_NODELAY ))
354342
355- nonlocal CNT
356- CNT += 1
357-
358343 writer .close ()
359344
360- async def client_2 (addr ):
345+ self ._test_create_connection_1 (client )
346+
347+ def test_create_connection_open_con_sock (self ):
348+ async def client (addr ):
361349 sock = socket .socket ()
362350 sock .connect (addr )
363351 reader , writer = await asyncio .open_connection (
@@ -370,11 +358,28 @@ async def client_2(addr):
370358 writer .write (b'BBBB' )
371359 self .assertEqual (await reader .readexactly (4 ), b'SPAM' )
372360
361+ writer .close ()
362+
363+ self ._test_create_connection_1 (client )
364+
365+ def _test_create_connection_1 (self , client ):
366+ CNT = 0
367+ TOTAL_CNT = 100
368+
369+ def server (sock ):
370+ data = sock .recv_all (4 )
371+ self .assertEqual (data , b'AAAA' )
372+ sock .send (b'OK' )
373+
374+ data = sock .recv_all (4 )
375+ self .assertEqual (data , b'BBBB' )
376+ sock .send (b'SPAM' )
377+
378+ async def client_wrapper (addr ):
379+ await client (addr )
373380 nonlocal CNT
374381 CNT += 1
375382
376- writer .close ()
377-
378383 def run (coro ):
379384 nonlocal CNT
380385 CNT = 0
@@ -391,8 +396,7 @@ def run(coro):
391396
392397 self .assertEqual (CNT , TOTAL_CNT )
393398
394- run (client )
395- run (client_2 )
399+ run (client_wrapper )
396400
397401 def test_create_connection_2 (self ):
398402 sock = socket .socket ()
0 commit comments