From 16a927d806f8b69587223da33f5081a65a9b978c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Bal=C3=A1=C5=BE?= Date: Fri, 9 May 2025 12:08:54 +0200 Subject: [PATCH] test: test Cursor.results() method --- tests/test_cursor_common.py | 15 +++++++++++++++ tests/test_cursor_common_async.py | 15 +++++++++++++++ tests/test_cursor_server.py | 7 +++++++ tests/test_cursor_server_async.py | 7 +++++++ 4 files changed, 44 insertions(+) diff --git a/tests/test_cursor_common.py b/tests/test_cursor_common.py index 2d104daf7..c0732c1b0 100644 --- a/tests/test_cursor_common.py +++ b/tests/test_cursor_common.py @@ -910,3 +910,18 @@ def test_row_maker_returns_none(conn): assert list(cur) == recs stream = cur.stream(query) assert list(stream) == recs + + +@pytest.mark.parametrize("count", [1, 2]) +def test_results_after_execute(conn, count): + with conn.cursor() as cur: + cur.execute(";".join(["select 1"] * count)) + assert list(cur.results()) == [cur] * count + + +@pytest.mark.parametrize("count", [0, 1, 2]) +@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 diff --git a/tests/test_cursor_common_async.py b/tests/test_cursor_common_async.py index e219846e6..868117508 100644 --- a/tests/test_cursor_common_async.py +++ b/tests/test_cursor_common_async.py @@ -918,3 +918,18 @@ async def test_row_maker_returns_none(aconn): assert await alist(cur) == recs stream = cur.stream(query) assert await alist(stream) == recs + + +@pytest.mark.parametrize("count", [1, 2]) +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 + + +@pytest.mark.parametrize("count", [0, 1, 2]) +@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 diff --git a/tests/test_cursor_server.py b/tests/test_cursor_server.py index 7bcc30529..a22571cce 100644 --- a/tests/test_cursor_server.py +++ b/tests/test_cursor_server.py @@ -581,3 +581,10 @@ def test_row_maker_returns_none(conn): assert list(cur) == recs stream = cur.stream(query) assert list(stream) == recs + + +@pytest.mark.parametrize("count", [1]) +def test_results_after_execute(conn, count): + with conn.cursor() as cur: + cur.execute(";".join(["select 1"] * count)) + assert list(cur.results()) == [cur] * count diff --git a/tests/test_cursor_server_async.py b/tests/test_cursor_server_async.py index f3c57d56b..8bfb5ac44 100644 --- a/tests/test_cursor_server_async.py +++ b/tests/test_cursor_server_async.py @@ -587,3 +587,10 @@ async def test_row_maker_returns_none(aconn): assert await alist(cur) == recs stream = cur.stream(query) assert await alist(stream) == recs + + +@pytest.mark.parametrize("count", [1]) +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 -- 2.47.3