Skip to content

Add tests for mixed methods or result iteration #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/unit/async_/work/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,36 @@ async def test_result_iteration(method, records):
await fetch_and_compare_all_records(result, "x", records, method)


@mark_async_test
async def test_result_iteration_mixed_methods():
records = [[i] for i in range(10)]
connection = AsyncConnectionStub(records=Records(["x"], records))
result = AsyncResult(connection, HydratorStub(), 4, noop, noop)
await result._run("CYPHER", {}, None, None, "r", None)
iter1 = AsyncUtil.iter(result)
iter2 = AsyncUtil.iter(result)
assert (await AsyncUtil.next(iter1)).get("x") == records[0][0]
assert (await AsyncUtil.next(iter2)).get("x") == records[1][0]
assert (await AsyncUtil.next(iter2)).get("x") == records[2][0]
assert (await AsyncUtil.next(iter1)).get("x") == records[3][0]
assert (await AsyncUtil.next(iter1)).get("x") == records[4][0]
assert (await AsyncUtil.next(result)).get("x") == records[5][0]
assert (await AsyncUtil.next(iter2)).get("x") == records[6][0]
assert (await AsyncUtil.next(iter1)).get("x") == records[7][0]
assert ((await AsyncUtil.next(AsyncUtil.iter(result))).get("x")
== records[8][0])
assert [r.get("x") async for r in result] == [records[9][0]]
with pytest.raises(StopAsyncIteration):
await AsyncUtil.next(iter1)
with pytest.raises(StopAsyncIteration):
await AsyncUtil.next(iter2)
with pytest.raises(StopAsyncIteration):
await AsyncUtil.next(result)
with pytest.raises(StopAsyncIteration):
await AsyncUtil.next(AsyncUtil.iter(result))
assert [r.get("x") async for r in result] == []


@pytest.mark.parametrize("method",
("for loop", "next", "one iter", "new iter"))
@pytest.mark.parametrize("invert_fetch", (True, False))
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/sync/work/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,36 @@ def test_result_iteration(method, records):
fetch_and_compare_all_records(result, "x", records, method)


@mark_sync_test
def test_result_iteration_mixed_methods():
records = [[i] for i in range(10)]
connection = ConnectionStub(records=Records(["x"], records))
result = Result(connection, HydratorStub(), 4, noop, noop)
result._run("CYPHER", {}, None, None, "r", None)
iter1 = Util.iter(result)
iter2 = Util.iter(result)
assert (Util.next(iter1)).get("x") == records[0][0]
assert (Util.next(iter2)).get("x") == records[1][0]
assert (Util.next(iter2)).get("x") == records[2][0]
assert (Util.next(iter1)).get("x") == records[3][0]
assert (Util.next(iter1)).get("x") == records[4][0]
assert (Util.next(result)).get("x") == records[5][0]
assert (Util.next(iter2)).get("x") == records[6][0]
assert (Util.next(iter1)).get("x") == records[7][0]
assert ((Util.next(Util.iter(result))).get("x")
== records[8][0])
assert [r.get("x") for r in result] == [records[9][0]]
with pytest.raises(StopIteration):
Util.next(iter1)
with pytest.raises(StopIteration):
Util.next(iter2)
with pytest.raises(StopIteration):
Util.next(result)
with pytest.raises(StopIteration):
Util.next(Util.iter(result))
assert [r.get("x") for r in result] == []


@pytest.mark.parametrize("method",
("for loop", "next", "one iter", "new iter"))
@pytest.mark.parametrize("invert_fetch", (True, False))
Expand Down