]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Add test for row_factory with cursor.stream()
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 24 Feb 2021 18:07:21 +0000 (19:07 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 24 Feb 2021 18:16:15 +0000 (19:16 +0100)
tests/test_cursor.py
tests/test_cursor_async.py

index 5cd21bb49216e082d0ac340278364d2710651f53..014d61d909b1e7fe618b285ebc06733f4bddfe4d 100644 (file)
@@ -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",
     [
index 1159c8ea574427660252b8ce7dd37b4cb598fe0a..5b0e542b1755f1225fac54fa7236e56ca439b6a9 100644 (file)
@@ -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",
     [