Skip to content

Commit 0ab4b19

Browse files
committed
Test calling async method
1 parent ce74b2f commit 0ab4b19

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

mypyc/test-data/run-async.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ def test_indirect_call() -> None:
107107
with assertRaises(MyError):
108108
asyncio.run(indirect_call_3(ident(-113.0, True)))
109109

110+
class C:
111+
def __init__(self, n: int) -> None:
112+
self.n = n
113+
114+
async def add(self, x: int, err: bool = False) -> int:
115+
await asyncio.sleep(0)
116+
if err:
117+
raise MyError()
118+
return x + self.n
119+
120+
async def method_call(x: int) -> int:
121+
c = C(5)
122+
return await c.add(x)
123+
124+
async def method_call_exception() -> int:
125+
c = C(5)
126+
return await c.add(3, err=True)
127+
128+
def test_async_method_call() -> None:
129+
assert asyncio.run(method_call(3)) == 8
130+
with assertRaises(MyError):
131+
asyncio.run(method_call_exception())
132+
110133
[file asyncio/__init__.pyi]
111134
async def sleep(t: float) -> None: ...
112135
# eh, we could use the real type but it doesn't seem important

0 commit comments

Comments
 (0)