Skip to content

Commit a8d3985

Browse files
committed
Rewrote the whole implementation of Cursor
1 parent 8c287e0 commit a8d3985

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

python/tests/test_cursor.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import math
2+
13
import pytest
24

3-
from psqlpy import Cursor
5+
from psqlpy import Cursor, PSQLPool, QueryResult, Transaction
46

57
pytestmark = pytest.mark.anyio
68

@@ -147,3 +149,25 @@ async def test_cursor_fetch_backward_all(
147149

148150
must_not_be_empty = await test_cursor.fetch_backward_all()
149151
assert len(must_not_be_empty.result()) == default_fetch_number - 1
152+
153+
154+
async def test_cursor_as_async_manager(
155+
psql_pool: PSQLPool,
156+
table_name: str,
157+
number_database_records: int,
158+
) -> None:
159+
"""Test cursor async manager and async iterator."""
160+
connection = await psql_pool.connection()
161+
transaction: Transaction
162+
cursor: Cursor
163+
all_results: list[QueryResult] = []
164+
expected_num_results = math.ceil(number_database_records / 3)
165+
fetch_number = 3
166+
async with connection.transaction() as transaction, transaction.cursor(
167+
querystring=f"SELECT * FROM {table_name}",
168+
fetch_number=fetch_number,
169+
) as cursor:
170+
async for result in cursor:
171+
all_results.append(result)
172+
173+
assert len(all_results) == expected_num_results

0 commit comments

Comments
 (0)