Skip to content

Commit e5284d9

Browse files
committed
pythongh-128404: remove requires_working_socket from some of test_asyncgen.py
1 parent 4ed36d6 commit e5284d9

File tree

1 file changed

+19
-70
lines changed

1 file changed

+19
-70
lines changed

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
@@ -620,6 +584,7 @@ async def agenfn():
620584
gen.close()
621585

622586

587+
@requires_working_socket()
623588
class AsyncGenAsyncioTest(unittest.TestCase):
624589

625590
def setUp(self):
@@ -710,7 +675,6 @@ async def __anext__(self):
710675
self.check_async_iterator_anext(MyAsyncIter)
711676

712677
def test_python_async_iterator_types_coroutine_anext(self):
713-
import types
714678
class MyAsyncIterWithTypesCoro:
715679
"""Asynchronously yield 1, then 2."""
716680
def __init__(self):
@@ -852,10 +816,6 @@ async def do_test():
852816
self.assertEqual(result, "completed")
853817

854818
def test_anext_iter(self):
855-
@types.coroutine
856-
def _async_yield(v):
857-
return (yield v)
858-
859819
class MyError(Exception):
860820
pass
861821

@@ -897,16 +857,15 @@ def test3(anext):
897857
self.assertEqual(g.send(None), 1)
898858

899859
def test4(anext):
900-
@types.coroutine
901-
def _async_yield(v):
902-
yield v * 10
903-
return (yield (v * 10 + 1))
860+
async def yield_twice(v):
861+
await _async_yield(v*10)
862+
return await _async_yield(v*10 + 1)
904863

905864
async def agenfn():
906865
try:
907-
await _async_yield(1)
866+
await yield_twice(1)
908867
except MyError:
909-
await _async_yield(2)
868+
await yield_twice(2)
910869
return
911870
yield
912871

@@ -918,14 +877,13 @@ async def agenfn():
918877
g.throw(MyError('val'))
919878

920879
def test5(anext):
921-
@types.coroutine
922-
def _async_yield(v):
923-
yield v * 10
924-
return (yield (v * 10 + 1))
880+
async def yield_twice(v):
881+
await _async_yield(v*10)
882+
return await _async_yield(v*10 + 1)
925883

926884
async def agenfn():
927885
try:
928-
await _async_yield(1)
886+
await yield_twice(1)
929887
except MyError:
930888
return
931889
yield 'aaa'
@@ -937,13 +895,12 @@ async def agenfn():
937895
g.throw(MyError())
938896

939897
def test6(anext):
940-
@types.coroutine
941-
def _async_yield(v):
942-
yield v * 10
943-
return (yield (v * 10 + 1))
898+
async def yield_twice(v):
899+
await _async_yield(v*10)
900+
return await _async_yield(v*10 + 1)
944901

945902
async def agenfn():
946-
await _async_yield(1)
903+
await yield_twice(1)
947904
yield 'aaa'
948905

949906
agen = agenfn()
@@ -2010,10 +1967,6 @@ class MyException(Exception):
20101967
gc_collect() # does not warn unawaited
20111968

20121969
def test_asend_send_already_running(self):
2013-
@types.coroutine
2014-
def _async_yield(v):
2015-
return (yield v)
2016-
20171970
async def agenfn():
20181971
while True:
20191972
await _async_yield(1)
@@ -2034,10 +1987,6 @@ async def agenfn():
20341987

20351988

20361989
def test_athrow_send_already_running(self):
2037-
@types.coroutine
2038-
def _async_yield(v):
2039-
return (yield v)
2040-
20411990
async def agenfn():
20421991
while True:
20431992
await _async_yield(1)

0 commit comments

Comments
 (0)