From: Daniele Varrazzo Date: Sun, 1 May 2022 20:45:24 +0000 (+0200) Subject: test: add cursor.stream() test for empty result sets X-Git-Tag: 3.1~125^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffe68f8d6deca4a241f29f121577c81b04550ad0;p=thirdparty%2Fpsycopg.git test: add cursor.stream() test for empty result sets Also add a missing async test for results with no column. --- diff --git a/tests/test_cursor.py b/tests/test_cursor.py index dad132428..646304240 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -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( diff --git a/tests/test_cursor_async.py b/tests/test_cursor_async.py index e372715a3..78aeafd5a 100644 --- a/tests/test_cursor_async.py +++ b/tests/test_cursor_async.py @@ -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", [