Skip to content

Commit 99221cc

Browse files
authored
Add tests for mixed methods or result iteration (#681)
1 parent 23b2a80 commit 99221cc

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tests/unit/async_/work/test_result.py

+30
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,36 @@ async def test_result_iteration(method, records):
252252
await fetch_and_compare_all_records(result, "x", records, method)
253253

254254

255+
@mark_async_test
256+
async def test_result_iteration_mixed_methods():
257+
records = [[i] for i in range(10)]
258+
connection = AsyncConnectionStub(records=Records(["x"], records))
259+
result = AsyncResult(connection, HydratorStub(), 4, noop, noop)
260+
await result._run("CYPHER", {}, None, None, "r", None)
261+
iter1 = AsyncUtil.iter(result)
262+
iter2 = AsyncUtil.iter(result)
263+
assert (await AsyncUtil.next(iter1)).get("x") == records[0][0]
264+
assert (await AsyncUtil.next(iter2)).get("x") == records[1][0]
265+
assert (await AsyncUtil.next(iter2)).get("x") == records[2][0]
266+
assert (await AsyncUtil.next(iter1)).get("x") == records[3][0]
267+
assert (await AsyncUtil.next(iter1)).get("x") == records[4][0]
268+
assert (await AsyncUtil.next(result)).get("x") == records[5][0]
269+
assert (await AsyncUtil.next(iter2)).get("x") == records[6][0]
270+
assert (await AsyncUtil.next(iter1)).get("x") == records[7][0]
271+
assert ((await AsyncUtil.next(AsyncUtil.iter(result))).get("x")
272+
== records[8][0])
273+
assert [r.get("x") async for r in result] == [records[9][0]]
274+
with pytest.raises(StopAsyncIteration):
275+
await AsyncUtil.next(iter1)
276+
with pytest.raises(StopAsyncIteration):
277+
await AsyncUtil.next(iter2)
278+
with pytest.raises(StopAsyncIteration):
279+
await AsyncUtil.next(result)
280+
with pytest.raises(StopAsyncIteration):
281+
await AsyncUtil.next(AsyncUtil.iter(result))
282+
assert [r.get("x") async for r in result] == []
283+
284+
255285
@pytest.mark.parametrize("method",
256286
("for loop", "next", "one iter", "new iter"))
257287
@pytest.mark.parametrize("invert_fetch", (True, False))

tests/unit/sync/work/test_result.py

+30
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,36 @@ def test_result_iteration(method, records):
252252
fetch_and_compare_all_records(result, "x", records, method)
253253

254254

255+
@mark_sync_test
256+
def test_result_iteration_mixed_methods():
257+
records = [[i] for i in range(10)]
258+
connection = ConnectionStub(records=Records(["x"], records))
259+
result = Result(connection, HydratorStub(), 4, noop, noop)
260+
result._run("CYPHER", {}, None, None, "r", None)
261+
iter1 = Util.iter(result)
262+
iter2 = Util.iter(result)
263+
assert (Util.next(iter1)).get("x") == records[0][0]
264+
assert (Util.next(iter2)).get("x") == records[1][0]
265+
assert (Util.next(iter2)).get("x") == records[2][0]
266+
assert (Util.next(iter1)).get("x") == records[3][0]
267+
assert (Util.next(iter1)).get("x") == records[4][0]
268+
assert (Util.next(result)).get("x") == records[5][0]
269+
assert (Util.next(iter2)).get("x") == records[6][0]
270+
assert (Util.next(iter1)).get("x") == records[7][0]
271+
assert ((Util.next(Util.iter(result))).get("x")
272+
== records[8][0])
273+
assert [r.get("x") for r in result] == [records[9][0]]
274+
with pytest.raises(StopIteration):
275+
Util.next(iter1)
276+
with pytest.raises(StopIteration):
277+
Util.next(iter2)
278+
with pytest.raises(StopIteration):
279+
Util.next(result)
280+
with pytest.raises(StopIteration):
281+
Util.next(Util.iter(result))
282+
assert [r.get("x") for r in result] == []
283+
284+
255285
@pytest.mark.parametrize("method",
256286
("for loop", "next", "one iter", "new iter"))
257287
@pytest.mark.parametrize("invert_fetch", (True, False))

0 commit comments

Comments
 (0)