From aa9cfe3491ba0c1883b02c60341fac49f53969c8 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 12 Jul 2025 07:42:59 +0200 Subject: [PATCH] test: more comprehensive results() tests Test the records returned, not only the generator results. --- tests/test_cursor_common.py | 23 +++++++++++++++++------ tests/test_cursor_common_async.py | 23 +++++++++++++++++------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/tests/test_cursor_common.py b/tests/test_cursor_common.py index c0732c1b0..c5e07297a 100644 --- a/tests/test_cursor_common.py +++ b/tests/test_cursor_common.py @@ -912,16 +912,27 @@ def test_row_maker_returns_none(conn): assert list(stream) == recs -@pytest.mark.parametrize("count", [1, 2]) +@pytest.mark.parametrize("count", [1, 3]) def test_results_after_execute(conn, count): with conn.cursor() as cur: - cur.execute(";".join(["select 1"] * count)) - assert list(cur.results()) == [cur] * count + cur.execute( + ";".join((f"select * from generate_series(1, {i})" for i in range(count))) + ) + ress = list((res.fetchall() for res in cur.results())) + assert ress == [[(j + 1,) for j in range(i)] for i in range(count)] -@pytest.mark.parametrize("count", [0, 1, 2]) +@pytest.mark.parametrize("count", [0, 1, 3]) @pytest.mark.parametrize("returning", [False, True]) def test_results_after_executemany(conn, count, returning): with conn.cursor() as cur: - cur.executemany("select 1", [()] * count, returning=returning) - assert list(cur.results()) == [cur] * returning * count + cur.executemany( + ph(cur, "select * from generate_series(1, %s)"), + [(i,) for i in range(count)], + returning=returning, + ) + ress = list((res.fetchall() for res in cur.results())) + if returning: + assert ress == [[(j + 1,) for j in range(i)] for i in range(count)] + else: + assert ress == [] diff --git a/tests/test_cursor_common_async.py b/tests/test_cursor_common_async.py index 868117508..600f254a9 100644 --- a/tests/test_cursor_common_async.py +++ b/tests/test_cursor_common_async.py @@ -920,16 +920,27 @@ async def test_row_maker_returns_none(aconn): assert await alist(stream) == recs -@pytest.mark.parametrize("count", [1, 2]) +@pytest.mark.parametrize("count", [1, 3]) async def test_results_after_execute(aconn, count): async with aconn.cursor() as cur: - await cur.execute(";".join(["select 1"] * count)) - assert await alist(cur.results()) == [cur] * count + await cur.execute( + ";".join(f"select * from generate_series(1, {i})" for i in range(count)) + ) + ress = await alist(await res.fetchall() async for res in cur.results()) + assert ress == [[(j + 1,) for j in range(i)] for i in range(count)] -@pytest.mark.parametrize("count", [0, 1, 2]) +@pytest.mark.parametrize("count", [0, 1, 3]) @pytest.mark.parametrize("returning", [False, True]) async def test_results_after_executemany(aconn, count, returning): async with aconn.cursor() as cur: - await cur.executemany("select 1", [()] * count, returning=returning) - assert await alist(cur.results()) == [cur] * returning * count + await cur.executemany( + ph(cur, "select * from generate_series(1, %s)"), + [(i,) for i in range(count)], + returning=returning, + ) + ress = await alist(await res.fetchall() async for res in cur.results()) + if returning: + assert ress == [[(j + 1,) for j in range(i)] for i in range(count)] + else: + assert ress == [] -- 2.47.2