From: Martin Baláž Date: Fri, 9 May 2025 10:08:54 +0000 (+0200) Subject: test: test Cursor.results() method X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=16a927d806f8b69587223da33f5081a65a9b978c;p=thirdparty%2Fpsycopg.git test: test Cursor.results() method --- 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