@@ -318,19 +318,7 @@ async def test():
318
318
319
319
self .loop .run_until_complete (test ())
320
320
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 ):
334
322
async def client (addr ):
335
323
reader , writer = await asyncio .open_connection (
336
324
* addr ,
@@ -352,12 +340,12 @@ async def client(addr):
352
340
self .assertTrue (
353
341
sock .getsockopt (socket .IPPROTO_TCP , socket .TCP_NODELAY ))
354
342
355
- nonlocal CNT
356
- CNT += 1
357
-
358
343
writer .close ()
359
344
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 ):
361
349
sock = socket .socket ()
362
350
sock .connect (addr )
363
351
reader , writer = await asyncio .open_connection (
@@ -370,11 +358,28 @@ async def client_2(addr):
370
358
writer .write (b'BBBB' )
371
359
self .assertEqual (await reader .readexactly (4 ), b'SPAM' )
372
360
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 )
373
380
nonlocal CNT
374
381
CNT += 1
375
382
376
- writer .close ()
377
-
378
383
def run (coro ):
379
384
nonlocal CNT
380
385
CNT = 0
@@ -391,8 +396,7 @@ def run(coro):
391
396
392
397
self .assertEqual (CNT , TOTAL_CNT )
393
398
394
- run (client )
395
- run (client_2 )
399
+ run (client_wrapper )
396
400
397
401
def test_create_connection_2 (self ):
398
402
sock = socket .socket ()
0 commit comments