From: Suresh Kumar Date: Sat, 30 Oct 2021 14:28:27 +0000 (+0530) Subject: added async cursor close tests for fetchone, fetchmany, fetchall X-Git-Tag: 3.0.2~11^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f190cd6ee9d7a5310f54aaedfb34cc70b51d24e;p=thirdparty%2Fpsycopg.git added async cursor close tests for fetchone, fetchmany, fetchall --- diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 8948f50c5..f6d01136b 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -42,19 +42,6 @@ def test_cursor_close_fetchone(conn): cur.fetchone() -def test_cursor_close_fetchmany(conn): - cur = conn.cursor() - assert not cur.closed - - query = "select * from generate_series(1, 10)" - cur.execute(query) - cur.close() - assert cur.closed - - with pytest.raises(psycopg.InterfaceError): - cur.fetchmany(1) - - def test_cursor_close_fetchmany(conn): cur = conn.cursor() assert not cur.closed diff --git a/tests/test_cursor_async.py b/tests/test_cursor_async.py index 325285b87..5ff9ea770 100644 --- a/tests/test_cursor_async.py +++ b/tests/test_cursor_async.py @@ -26,6 +26,52 @@ async def test_close(aconn): assert cur.closed +async def test_cursor_close_fetchone(aconn): + cur = aconn.cursor() + assert not cur.closed + + query = "select * from generate_series(1, 10)" + await cur.execute(query) + for _ in range(5): + await cur.fetchone() + + await cur.close() + assert cur.closed + + with pytest.raises(psycopg.InterfaceError): + await cur.fetchone() + + +async def test_cursor_close_fetchmany(aconn): + cur = aconn.cursor() + assert not cur.closed + + query = "select * from generate_series(1, 10)" + await cur.execute(query) + assert len(await cur.fetchmany(2)) == 2 + + await cur.close() + assert cur.closed + + with pytest.raises(psycopg.InterfaceError): + await cur.fetchmany(2) + + +async def test_cursor_close_fetchall(aconn): + cur = aconn.cursor() + assert not cur.closed + + query = "select * from generate_series(1, 10)" + await cur.execute(query) + assert len(await cur.fetchall()) == 10 + + await cur.close() + assert cur.closed + + with pytest.raises(psycopg.InterfaceError): + await cur.fetchall() + + async def test_context(aconn): async with aconn.cursor() as cur: assert not cur.closed