From ffe68f8d6deca4a241f29f121577c81b04550ad0 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 1 May 2022 22:45:24 +0200 Subject: [PATCH] test: add cursor.stream() test for empty result sets Also add a missing async test for results with no column. --- tests/test_cursor.py | 10 ++++++++-- tests/test_cursor_async.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) 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", [ -- 2.47.2