From: Daniele Varrazzo Date: Wed, 24 Feb 2021 18:07:21 +0000 (+0100) Subject: Add test for row_factory with cursor.stream() X-Git-Tag: 3.0.dev0~106^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc7d1df54b3e208ec3f0029636d8b2fb11e21e8b;p=thirdparty%2Fpsycopg.git Add test for row_factory with cursor.stream() --- diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 5cd21bb49..014d61d90 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -404,6 +404,14 @@ def test_stream_sql(conn): assert recs == [(1, dt.date(2021, 1, 2)), (2, dt.date(2021, 1, 3))] +def test_stream_row_factory(conn): + cur = conn.cursor(row_factory=rows.dict_row) + it = iter(cur.stream("select generate_series(1,2) as a")) + assert next(it)["a"] == 1 + cur.row_factory = rows.namedtuple_row + assert next(it).a == 2 + + @pytest.mark.parametrize( "query", [ diff --git a/tests/test_cursor_async.py b/tests/test_cursor_async.py index 1159c8ea5..5b0e542b1 100644 --- a/tests/test_cursor_async.py +++ b/tests/test_cursor_async.py @@ -410,6 +410,14 @@ async def test_stream_sql(aconn): assert recs == [(1, dt.date(2021, 1, 2)), (2, dt.date(2021, 1, 3))] +async def test_stream_row_factory(aconn): + cur = aconn.cursor(row_factory=rows.dict_row) + ait = cur.stream("select generate_series(1,2) as a") + assert (await ait.__anext__())["a"] == 1 + cur.row_factory = rows.namedtuple_row + assert (await ait.__anext__()).a == 2 + + @pytest.mark.parametrize( "query", [