From: Daniele Varrazzo Date: Wed, 10 Feb 2021 01:05:31 +0000 (+0100) Subject: Add scrollable tests X-Git-Tag: 3.0.dev0~115^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e74d749ab435d31138b8ea40a1d39d4fc3f71d5;p=thirdparty%2Fpsycopg.git Add scrollable tests --- diff --git a/tests/test_named_cursor.py b/tests/test_named_cursor.py index 2961d96cb..252bb88b6 100644 --- a/tests/test_named_cursor.py +++ b/tests/test_named_cursor.py @@ -148,3 +148,21 @@ def test_scroll(conn): with pytest.raises(ValueError): cur.scroll(9, mode="wat") + + +def test_scrollable(conn): + curs = conn.cursor("foo") + curs.execute("select generate_series(0, 5)") + curs.scroll(5) + for i in range(4, -1, -1): + curs.scroll(-1) + assert i == curs.fetchone()[0] + curs.scroll(-1) + + +def test_non_scrollable(conn): + curs = conn.cursor("foo") + curs.execute("select generate_series(0, 5)", scrollable=False) + curs.scroll(5) + with pytest.raises(conn.OperationalError): + curs.scroll(-1) diff --git a/tests/test_named_cursor_async.py b/tests/test_named_cursor_async.py index 1dd643b41..568b31201 100644 --- a/tests/test_named_cursor_async.py +++ b/tests/test_named_cursor_async.py @@ -155,3 +155,21 @@ async def test_scroll(aconn): with pytest.raises(ValueError): await cur.scroll(9, mode="wat") + + +async def test_scrollable(aconn): + curs = await aconn.cursor("foo") + await curs.execute("select generate_series(0, 5)") + await curs.scroll(5) + for i in range(4, -1, -1): + await curs.scroll(-1) + assert i == (await curs.fetchone())[0] + await curs.scroll(-1) + + +async def test_non_scrollable(aconn): + curs = await aconn.cursor("foo") + await curs.execute("select generate_series(0, 5)", scrollable=False) + await curs.scroll(5) + with pytest.raises(aconn.OperationalError): + await curs.scroll(-1)