Skip to content

Commit 639d914

Browse files
committed
Python: test Awaitable, framework for async test
1 parent 0247877 commit 639d914

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

python/ql/test/experimental/dataflow/coverage/classes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,17 +1253,17 @@ def test_exit():
12531253
with With_exit():
12541254
pass
12551255

1256-
# # 3.4.1. Awaitable Objects
1257-
# # object.__await__(self)
1258-
# class With_await:
1256+
# 3.4.1. Awaitable Objects
1257+
# object.__await__(self)
1258+
class With_await:
12591259

1260-
# def __await__(self):
1261-
# OK()
1262-
# return "" # edit to match type
1260+
def __await__(self):
1261+
OK()
1262+
return (yield from asyncio.coroutine(lambda: "")())
12631263

1264-
# async def test_await():
1265-
# with_await = With_await()
1266-
# await(with_await) # edit to effect call
1264+
async def atest_await():
1265+
with_await = With_await()
1266+
await(with_await)
12671267

12681268

12691269
# # 3.4.2. Coroutine Objects

python/ql/test/experimental/dataflow/coverage/validTest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ def check_test_function(f):
1515
sys.stdout = old_stdout
1616
check_output(capturer.getvalue(), f)
1717

18+
def check_async_test_function(f):
19+
from io import StringIO
20+
import sys
21+
import asyncio
22+
23+
capturer = StringIO()
24+
old_stdout = sys.stdout
25+
sys.stdout = capturer
26+
asyncio.run(f())
27+
sys.stdout = old_stdout
28+
check_output(capturer.getvalue(), f)
29+
1830
def check_classes_valid(testFile):
1931
# import python.ql.test.experimental.dataflow.coverage.classes as tests
2032
# import classes as tests
@@ -28,6 +40,12 @@ def check_classes_valid(testFile):
2840
print("Checking", testFile, item)
2941
check_test_function(item)
3042

43+
elif i.startswith("atest_"):
44+
item = getattr(tests,i)
45+
if callable(item):
46+
print("Checking", testFile, item)
47+
check_async_test_function(item)
48+
3149
if __name__ == '__main__':
3250
check_classes_valid("classes")
3351
check_classes_valid("test")

0 commit comments

Comments
 (0)