Skip to content

Commit f53a0f5

Browse files
committed
support wasi/emscripten on pdb tests
1 parent 5c814c8 commit f53a0f5

File tree

4 files changed

+58
-50
lines changed

4 files changed

+58
-50
lines changed

Lib/test/support/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,3 +2940,31 @@ def in_systemd_nspawn_sync_suppressed() -> bool:
29402940
os.close(fd)
29412941

29422942
return False
2943+
2944+
def run_simple_async_fn(async_fn, /, *args, **kwargs):
2945+
coro = async_fn(*args, **kwargs)
2946+
try:
2947+
coro.send(None)
2948+
except StopIteration as e:
2949+
return e.value
2950+
else:
2951+
raise AssertionError("coroutine did not complete")
2952+
finally:
2953+
coro.close()
2954+
2955+
2956+
@types.coroutine
2957+
def async_yield(v):
2958+
return (yield v)
2959+
2960+
2961+
def run_async_fn(async_fn, /, *args, **kwargs):
2962+
coro = async_fn(*args, **kwargs)
2963+
try:
2964+
while True:
2965+
try:
2966+
coro.send(None)
2967+
except StopIteration as e:
2968+
return e.value
2969+
finally:
2970+
coro.close()

Lib/test/test_contextlib_async.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,13 @@
33
asynccontextmanager, AbstractAsyncContextManager,
44
AsyncExitStack, nullcontext, aclosing, contextmanager)
55
from test import support
6+
from test.support import run_simple_async_fn as _run_async_fn
67
import unittest
78
import traceback
89

910
from test.test_contextlib import TestBaseExitStack
1011

1112

12-
def _run_async_fn(async_fn, /, *args, **kwargs):
13-
coro = async_fn(*args, **kwargs)
14-
try:
15-
coro.send(None)
16-
except StopIteration as e:
17-
return e.value
18-
else:
19-
raise AssertionError("coroutine did not complete")
20-
finally:
21-
coro.close()
22-
23-
2413
def _async_test(async_fn):
2514
"""Decorator to turn an async function into a synchronous function"""
2615
@functools.wraps(async_fn)

Lib/test/test_inspect/test_inspect.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,15 +1161,7 @@ def f(self):
11611161
sys.modules.pop("inspect_actual")
11621162

11631163
def test_nested_class_definition_inside_async_function(self):
1164-
def run(coro):
1165-
try:
1166-
coro.send(None)
1167-
except StopIteration as e:
1168-
return e.value
1169-
else:
1170-
raise RuntimeError("coroutine did not complete synchronously!")
1171-
finally:
1172-
coro.close()
1164+
from test.support import run_simple_async_fn as run
11731165

11741166
self.assertSourceEqual(run(mod2.func225()), 226, 227)
11751167
self.assertSourceEqual(mod2.cls226, 231, 235)

Lib/test/test_pdb.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
from test.support.pty_helper import run_pty, FakeInput
2121
from unittest.mock import patch
2222

23-
# gh-114275: WASI fails to run asyncio tests, similar skip than test_asyncio.
24-
SKIP_ASYNCIO_TESTS = (not support.has_socket_support)
23+
SKIP_CORO_TESTS = False
2524

2625

2726
class PdbTestInput(object):
@@ -2049,23 +2048,23 @@ def test_pdb_next_command_for_generator():
20492048
finished
20502049
"""
20512050

2052-
if not SKIP_ASYNCIO_TESTS:
2051+
if not SKIP_CORO_TESTS:
20532052
def test_pdb_next_command_for_coroutine():
20542053
"""Testing skip unwindng stack on yield for coroutines for "next" command
20552054
2056-
>>> import asyncio
2055+
>>> from test.support import run_async_fn, async_yield
20572056
20582057
>>> async def test_coro():
2059-
... await asyncio.sleep(0)
2060-
... await asyncio.sleep(0)
2061-
... await asyncio.sleep(0)
2058+
... await async_yield(0)
2059+
... await async_yield(0)
2060+
... await async_yield(0)
20622061
20632062
>>> async def test_main():
20642063
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
20652064
... await test_coro()
20662065
20672066
>>> def test_function():
2068-
... asyncio.run(test_main())
2067+
... run_async_fn(test_main)
20692068
... print("finished")
20702069
20712070
>>> with PdbTestInput(['step',
@@ -2088,13 +2087,13 @@ def test_pdb_next_command_for_coroutine():
20882087
-> async def test_coro():
20892088
(Pdb) step
20902089
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(2)test_coro()
2091-
-> await asyncio.sleep(0)
2090+
-> await async_yield(0)
20922091
(Pdb) next
20932092
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(3)test_coro()
2094-
-> await asyncio.sleep(0)
2093+
-> await async_yield(0)
20952094
(Pdb) next
20962095
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[1]>(4)test_coro()
2097-
-> await asyncio.sleep(0)
2096+
-> await async_yield(0)
20982097
(Pdb) next
20992098
Internal StopIteration
21002099
> <doctest test.test_pdb.test_pdb_next_command_for_coroutine[2]>(3)test_main()
@@ -2110,11 +2109,11 @@ def test_pdb_next_command_for_coroutine():
21102109
def test_pdb_next_command_for_asyncgen():
21112110
"""Testing skip unwindng stack on yield for coroutines for "next" command
21122111
2113-
>>> import asyncio
2112+
>>> from test.support import run_async_fn, async_yield
21142113
21152114
>>> async def agen():
21162115
... yield 1
2117-
... await asyncio.sleep(0)
2116+
... await async_yield(0)
21182117
... yield 2
21192118
21202119
>>> async def test_coro():
@@ -2126,7 +2125,7 @@ def test_pdb_next_command_for_asyncgen():
21262125
... await test_coro()
21272126
21282127
>>> def test_function():
2129-
... asyncio.run(test_main())
2128+
... run_async_fn(test_main)
21302129
... print("finished")
21312130
21322131
>>> with PdbTestInput(['step',
@@ -2163,7 +2162,7 @@ def test_pdb_next_command_for_asyncgen():
21632162
-> yield 1
21642163
(Pdb) next
21652164
> <doctest test.test_pdb.test_pdb_next_command_for_asyncgen[1]>(3)agen()
2166-
-> await asyncio.sleep(0)
2165+
-> await async_yield(0)
21672166
(Pdb) continue
21682167
2
21692168
finished
@@ -2228,23 +2227,23 @@ def test_pdb_return_command_for_generator():
22282227
finished
22292228
"""
22302229

2231-
if not SKIP_ASYNCIO_TESTS:
2230+
if not SKIP_CORO_TESTS:
22322231
def test_pdb_return_command_for_coroutine():
22332232
"""Testing no unwindng stack on yield for coroutines for "return" command
22342233
2235-
>>> import asyncio
2234+
>>> from test.support import run_async_fn, async_yield
22362235
22372236
>>> async def test_coro():
2238-
... await asyncio.sleep(0)
2239-
... await asyncio.sleep(0)
2240-
... await asyncio.sleep(0)
2237+
... await async_yield(0)
2238+
... await async_yield(0)
2239+
... await async_yield(0)
22412240
22422241
>>> async def test_main():
22432242
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
22442243
... await test_coro()
22452244
22462245
>>> def test_function():
2247-
... asyncio.run(test_main())
2246+
... run_async_fn(test_main)
22482247
... print("finished")
22492248
22502249
>>> with PdbTestInput(['step',
@@ -2264,10 +2263,10 @@ def test_pdb_return_command_for_coroutine():
22642263
-> async def test_coro():
22652264
(Pdb) step
22662265
> <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(2)test_coro()
2267-
-> await asyncio.sleep(0)
2266+
-> await async_yield(0)
22682267
(Pdb) next
22692268
> <doctest test.test_pdb.test_pdb_return_command_for_coroutine[1]>(3)test_coro()
2270-
-> await asyncio.sleep(0)
2269+
-> await async_yield(0)
22712270
(Pdb) continue
22722271
finished
22732272
"""
@@ -2320,28 +2319,28 @@ def test_pdb_until_command_for_generator():
23202319
finished
23212320
"""
23222321

2323-
if not SKIP_ASYNCIO_TESTS:
2322+
if not SKIP_CORO_TESTS:
23242323
def test_pdb_until_command_for_coroutine():
23252324
"""Testing no unwindng stack for coroutines
23262325
for "until" command if target breakpoint is not reached
23272326
2328-
>>> import asyncio
2327+
>>> from test.support import run_async_fn, async_yield
23292328
23302329
>>> async def test_coro():
23312330
... print(0)
2332-
... await asyncio.sleep(0)
2331+
... await async_yield(0)
23332332
... print(1)
2334-
... await asyncio.sleep(0)
2333+
... await async_yield(0)
23352334
... print(2)
2336-
... await asyncio.sleep(0)
2335+
... await async_yield(0)
23372336
... print(3)
23382337
23392338
>>> async def test_main():
23402339
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
23412340
... await test_coro()
23422341
23432342
>>> def test_function():
2344-
... asyncio.run(test_main())
2343+
... run_async_fn(test_main)
23452344
... print("finished")
23462345
23472346
>>> with PdbTestInput(['step',

0 commit comments

Comments
 (0)