From: Denis Laxalde Date: Thu, 11 Feb 2021 16:40:23 +0000 (+0100) Subject: Add tests for cursor's row_factory with nextset() X-Git-Tag: 3.0.dev0~106^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85342f462f38dbf48ca6b6fb995e6632ac4a4732;p=thirdparty%2Fpsycopg.git Add tests for cursor's row_factory with nextset() --- diff --git a/tests/test_cursor.py b/tests/test_cursor.py index cdd9f6de1..9db2ab358 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -272,6 +272,12 @@ def test_row_factory(conn): r = cur.fetchall() assert r == [[-1], [-2], [-3]] + cur.execute("select 42; select generate_series(1,3)") + assert cur.fetchall() == [[-42]] + assert cur.nextset() + assert cur.fetchall() == [[-1], [-2], [-3]] + assert cur.nextset() is None + def test_query_params_execute(conn): cur = conn.cursor() diff --git a/tests/test_cursor_async.py b/tests/test_cursor_async.py index 1aa4f2198..fba7fb502 100644 --- a/tests/test_cursor_async.py +++ b/tests/test_cursor_async.py @@ -270,10 +270,9 @@ async def test_iter_stop(aconn): async def test_row_factory(aconn): def my_row_factory(cursor): - assert cursor.description is not None - titles = [c.name for c in cursor.description] - def mkrow(values): + assert cursor.description is not None + titles = [c.name for c in cursor.description] return [ f"{value.upper()}{title}" for title, value in zip(titles, values) @@ -286,6 +285,12 @@ async def test_row_factory(aconn): (r,) = await cur.fetchone() assert r == "FOObar" + await cur.execute("select 'x' as x; select 'y' as y, 'z' as z") + assert await cur.fetchall() == [["Xx"]] + assert cur.nextset() + assert await cur.fetchall() == [["Yy", "Zz"]] + assert cur.nextset() is None + async def test_query_params_execute(aconn): cur = await aconn.cursor()