File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 1+ import math
2+
13import pytest
24
3- from psqlpy import Cursor
5+ from psqlpy import Cursor , PSQLPool , QueryResult , Transaction
46
57pytestmark = 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
You can’t perform that action at this time.
0 commit comments