From: Daniele Varrazzo Date: Thu, 11 Feb 2021 20:59:03 +0000 (+0100) Subject: Add tests to verify row_factory works with server-side cursors too X-Git-Tag: 3.0.dev0~106^2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b3c9e4bbf090c97b6f0cb967784fecccf9b142c;p=thirdparty%2Fpsycopg.git Add tests to verify row_factory works with server-side cursors too --- 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