From 4b3c9e4bbf090c97b6f0cb967784fecccf9b142c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 11 Feb 2021 21:59:03 +0100 Subject: [PATCH] Add tests to verify row_factory works with server-side cursors too --- tests/test_server_cursor.py | 10 ++++++++++ tests/test_server_cursor_async.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/test_server_cursor.py b/tests/test_server_cursor.py index 551579e95..6e908a407 100644 --- a/tests/test_server_cursor.py +++ b/tests/test_server_cursor.py @@ -150,6 +150,16 @@ def test_nextset(conn): assert not cur.nextset() +def test_row_factory(conn): + def my_row_factory(cur): + return lambda values: [-v for v in values] + + cur = conn.cursor("foo", row_factory=my_row_factory) + cur.execute("select generate_series(1, 3)") + r = cur.fetchall() + assert r == [[-1], [-2], [-3]] + + def test_rownumber(conn): cur = conn.cursor("foo") assert cur.rownumber is None diff --git a/tests/test_server_cursor_async.py b/tests/test_server_cursor_async.py index fa2d9425c..5625cd885 100644 --- a/tests/test_server_cursor_async.py +++ b/tests/test_server_cursor_async.py @@ -152,6 +152,16 @@ async def test_nextset(aconn): assert not cur.nextset() +async def test_row_factory(aconn): + def my_row_factory(cur): + return lambda values: [-v for v in values] + + cur = aconn.cursor("foo", row_factory=my_row_factory) + await cur.execute("select generate_series(1, 3)") + r = await cur.fetchall() + assert r == [[-1], [-2], [-3]] + + async def test_rownumber(aconn): cur = aconn.cursor("foo") assert cur.rownumber is None -- 2.47.3