]> 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>
Mon, 2 May 2022 00:07:56 +0000 (02:07 +0200)
Also add a missing async test for results with no column.

tests/test_cursor.py
tests/test_cursor_async.py

index 2dfccfc84f91e4662bd9e7480cf69200b3fe4d96..35a6f483f9b5ee74cb0284791b6e10356ac52316 100644 (file)
@@ -543,10 +543,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 654d7d437d784d47e45766dce5e417b25da9cd5e..59e7986e22f25653f9ae10317f3b7771d38209aa 100644 (file)
@@ -535,6 +535,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",
     [