]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: add cursor.stream() test for empty result sets
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 1 May 2022 20:45:24 +0000 (22:45 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 1 May 2022 20:46:49 +0000 (22:46 +0200)
Also add a missing async test for results with no column.

tests/test_cursor.py
tests/test_cursor_async.py

index dad1324281b3b3433888ddf88370d2a22b519f9f..646304240c193f2892c20257333df3a8656f7ea3 100644 (file)
@@ -578,10 +578,16 @@ def test_stream_row_factory(conn):
     assert next(it).a == 2
 
 
+def test_stream_no_row(conn):
+    cur = conn.cursor()
+    recs = list(cur.stream("select generate_series(2,1) as a"))
+    assert recs == []
+
+
 def test_stream_no_col(conn):
     cur = conn.cursor()
-    it = iter(cur.stream("select"))
-    assert list(it) == [()]
+    recs = list(cur.stream("select"))
+    assert recs == [()]
 
 
 @pytest.mark.parametrize(
index e372715a3f8962044aa6c6b604d788267cbc6a20..78aeafd5a3faf3a7cb0f5d556b8fb90a17bcb299 100644 (file)
@@ -570,6 +570,18 @@ async def test_stream_row_factory(aconn):
     assert (await ait.__anext__()).a == 2
 
 
+async def test_stream_no_row(aconn):
+    cur = aconn.cursor()
+    recs = [rec async for rec in cur.stream("select generate_series(2,1) as a")]
+    assert recs == []
+
+
+async def test_stream_no_col(aconn):
+    cur = aconn.cursor()
+    recs = [rec async for rec in cur.stream("select")]
+    assert recs == [()]
+
+
 @pytest.mark.parametrize(
     "query",
     [