Skip to content

Commit bef6451

Browse files
committed
gh-128404: remove requires_working_socket from some of test_asyncgen.py
1 parent 486b000 commit bef6451

1 file changed

Lines changed: 19 additions & 70 deletions

File tree

‎Lib/test/test_asyncgen.py‎

Lines changed: 19 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1+
import asyncio
12
import inspect
23
import types
34
import unittest
45
import contextlib
56

67
from test.support.import_helper import import_module
7-
from test.support import gc_collect, requires_working_socket
8-
asyncio = import_module("asyncio")
8+
from test.support import gc_collect, requires_working_socket, async_yield as _async_yield
99

1010

11-
requires_working_socket(module=True)
12-
1311
_no_default = object()
1412

1513

1614
class AwaitException(Exception):
1715
pass
1816

1917

20-
@types.coroutine
21-
def awaitable(*, throw=False):
18+
async def awaitable(*, throw=False):
2219
if throw:
23-
yield ('throw',)
20+
await _async_yield(('throw',))
2421
else:
25-
yield ('result',)
22+
await _async_yield(('result',))
2623

2724

2825
def run_until_complete(coro):
@@ -398,12 +395,6 @@ async def gen():
398395
an.send(None)
399396

400397
def test_async_gen_asend_throw_concurrent_with_send(self):
401-
import types
402-
403-
@types.coroutine
404-
def _async_yield(v):
405-
return (yield v)
406-
407398
class MyExc(Exception):
408399
pass
409400

@@ -431,11 +422,6 @@ async def agenfn():
431422
gen2.send(None)
432423

433424
def test_async_gen_athrow_throw_concurrent_with_send(self):
434-
import types
435-
436-
@types.coroutine
437-
def _async_yield(v):
438-
return (yield v)
439425

440426
class MyExc(Exception):
441427
pass
@@ -464,12 +450,6 @@ async def agenfn():
464450
gen2.send(None)
465451

466452
def test_async_gen_asend_throw_concurrent_with_throw(self):
467-
import types
468-
469-
@types.coroutine
470-
def _async_yield(v):
471-
return (yield v)
472-
473453
class MyExc(Exception):
474454
pass
475455

@@ -502,11 +482,6 @@ async def agenfn():
502482
gen2.send(None)
503483

504484
def test_async_gen_athrow_throw_concurrent_with_throw(self):
505-
import types
506-
507-
@types.coroutine
508-
def _async_yield(v):
509-
return (yield v)
510485

511486
class MyExc(Exception):
512487
pass
@@ -572,12 +547,6 @@ async def gen():
572547
aclose.close()
573548

574549
def test_async_gen_asend_close_runtime_error(self):
575-
import types
576-
577-
@types.coroutine
578-
def _async_yield(v):
579-
return (yield v)
580-
581550
async def agenfn():
582551
try:
583552
await _async_yield(None)
@@ -593,11 +562,6 @@ async def agenfn():
593562
gen.close()
594563

595564
def test_async_gen_athrow_close_runtime_error(self):
596-
import types
597-
598-
@types.coroutine
599-
def _async_yield(v):
600-
return (yield v)
601565

602566
class MyExc(Exception):
603567
pass
@@ -647,6 +611,7 @@ async def agenfn():
647611
self.assertEqual(cm.exception.value, 2)
648612

649613

614+
@requires_working_socket()
650615
class AsyncGenAsyncioTest(unittest.TestCase):
651616

652617
def setUp(self):
@@ -737,7 +702,6 @@ async def __anext__(self):
737702
self.check_async_iterator_anext(MyAsyncIter)
738703

739704
def test_python_async_iterator_types_coroutine_anext(self):
740-
import types
741705
class MyAsyncIterWithTypesCoro:
742706
"""Asynchronously yield 1, then 2."""
743707
def __init__(self):
@@ -879,10 +843,6 @@ async def do_test():
879843
self.assertEqual(result, "completed")
880844

881845
def test_anext_iter(self):
882-
@types.coroutine
883-
def _async_yield(v):
884-
return (yield v)
885-
886846
class MyError(Exception):
887847
pass
888848

@@ -924,16 +884,15 @@ def test3(anext):
924884
self.assertEqual(g.send(None), 1)
925885

926886
def test4(anext):
927-
@types.coroutine
928-
def _async_yield(v):
929-
yield v * 10
930-
return (yield (v * 10 + 1))
887+
async def yield_twice(v):
888+
await _async_yield(v*10)
889+
return await _async_yield(v*10 + 1)
931890

932891
async def agenfn():
933892
try:
934-
await _async_yield(1)
893+
await yield_twice(1)
935894
except MyError:
936-
await _async_yield(2)
895+
await yield_twice(2)
937896
return
938897
yield
939898

@@ -945,14 +904,13 @@ async def agenfn():
945904
g.throw(MyError('val'))
946905

947906
def test5(anext):
948-
@types.coroutine
949-
def _async_yield(v):
950-
yield v * 10
951-
return (yield (v * 10 + 1))
907+
async def yield_twice(v):
908+
await _async_yield(v*10)
909+
return await _async_yield(v*10 + 1)
952910

953911
async def agenfn():
954912
try:
955-
await _async_yield(1)
913+
await yield_twice(1)
956914
except MyError:
957915
return
958916
yield 'aaa'
@@ -964,13 +922,12 @@ async def agenfn():
964922
g.throw(MyError())
965923

966924
def test6(anext):
967-
@types.coroutine
968-
def _async_yield(v):
969-
yield v * 10
970-
return (yield (v * 10 + 1))
925+
async def yield_twice(v):
926+
await _async_yield(v*10)
927+
return await _async_yield(v*10 + 1)
971928

972929
async def agenfn():
973-
await _async_yield(1)
930+
await yield_twice(1)
974931
yield 'aaa'
975932

976933
agen = agenfn()
@@ -2118,10 +2075,6 @@ class MyException(Exception):
21182075
gc_collect() # does not warn unawaited
21192076

21202077
def test_asend_send_already_running(self):
2121-
@types.coroutine
2122-
def _async_yield(v):
2123-
return (yield v)
2124-
21252078
async def agenfn():
21262079
while True:
21272080
await _async_yield(1)
@@ -2142,10 +2095,6 @@ async def agenfn():
21422095

21432096

21442097
def test_athrow_send_already_running(self):
2145-
@types.coroutine
2146-
def _async_yield(v):
2147-
return (yield v)
2148-
21492098
async def agenfn():
21502099
while True:
21512100
await _async_yield(1)

0 commit comments

Comments
 (0)