Skip to content

Commit 3929e01

Browse files
committed
Python: tests for async iterators/context managers
1 parent 681657f commit 3929e01

File tree

1 file changed

+48
-34
lines changed
  • python/ql/test/experimental/dataflow/coverage

1 file changed

+48
-34
lines changed

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

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,49 +1271,63 @@ async def atest_await():
12711271
# # coroutine.throw(type[, value[, traceback]])
12721272
# # coroutine.close()
12731273

1274-
# # 3.4.3. Asynchronous Iterators
1275-
# # object.__aiter__(self)
1276-
# class With_aiter:
1274+
# 3.4.3. Asynchronous Iterators
1275+
# object.__aiter__(self)
1276+
class With_aiter:
12771277

1278-
# def __aiter__(self):
1279-
# OK()
1280-
# return "" # edit to match type
1278+
def __aiter__(self):
1279+
OK()
1280+
return self
1281+
1282+
async def __anext__(self):
1283+
raise StopAsyncIteration
1284+
1285+
async def atest_aiter():
1286+
with_aiter = With_aiter()
1287+
async for x in with_aiter:
1288+
pass
1289+
1290+
# object.__anext__(self)
1291+
class With_anext:
1292+
1293+
def __aiter__(self):
1294+
return self
12811295

1282-
# def test_aiter():
1283-
# with_aiter = With_aiter()
1284-
# aiter(with_aiter) # edit to effect call
1296+
async def __anext__(self):
1297+
OK()
1298+
raise StopAsyncIteration
12851299

1286-
# # object.__anext__(self)
1287-
# class With_anext:
1300+
async def atest_anext():
1301+
with_anext = With_anext()
1302+
async for x in with_anext:
1303+
pass
12881304

1289-
# def __anext__(self):
1290-
# OK()
1291-
# return "" # edit to match type
12921305

1293-
# def test_anext():
1294-
# with_anext = With_anext()
1295-
# anext(with_anext) # edit to effect call
1306+
# 3.4.4. Asynchronous Context Managers
1307+
# object.__aenter__(self)
1308+
class With_aenter:
12961309

1310+
async def __aenter__(self):
1311+
OK()
12971312

1298-
# # 3.4.4. Asynchronous Context Managers
1299-
# # object.__aenter__(self)
1300-
# class With_aenter:
1313+
async def __aexit__(self, exc_type, exc_value, traceback):
1314+
pass
13011315

1302-
# def __aenter__(self):
1303-
# OK()
1304-
# return "" # edit to match type
1316+
async def atest_aenter():
1317+
with_aenter = With_aenter()
1318+
async with with_aenter:
1319+
pass
13051320

1306-
# def test_aenter():
1307-
# with_aenter = With_aenter()
1308-
# aenter(with_aenter) # edit to effect call
1321+
# object.__aexit__(self, exc_type, exc_value, traceback)
1322+
class With_aexit:
13091323

1310-
# # object.__aexit__(self, exc_type, exc_value, traceback)
1311-
# class With_aexit:
1324+
async def __aenter__(self):
1325+
pass
13121326

1313-
# def __aexit__(self, exc_type, exc_value, traceback):
1314-
# OK()
1315-
# return "" # edit to match type
1327+
async def __aexit__(self, exc_type, exc_value, traceback):
1328+
OK()
13161329

1317-
# def test_aexit():
1318-
# with_aexit = With_aexit()
1319-
# aexit(with_aexit) # edit to effect call
1330+
async def atest_aexit():
1331+
with_aexit = With_aexit()
1332+
async with with_aexit:
1333+
pass

0 commit comments

Comments
 (0)