]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
added async cursor close tests for fetchone, fetchmany, fetchall
authorSuresh Kumar <sureshdsk91@gmail.com>
Sat, 30 Oct 2021 14:28:27 +0000 (19:58 +0530)
committerSuresh Kumar <sureshdsk91@gmail.com>
Sat, 30 Oct 2021 14:34:04 +0000 (20:04 +0530)
tests/test_cursor.py
tests/test_cursor_async.py

index 8948f50c5694686d46132c2af732c33539fee429..f6d01136b8c7cf6b9a2d20f4be48a0d80eae612b 100644 (file)
@@ -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
index 325285b875ca4e217968b7e7c8f3a9c347005bb7..5ff9ea770b5a931921ed78fce042ce7b2aafa637 100644 (file)
@@ -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