| 29 | 'result != expected for prefetch={}'.format(prefetch)) |
| 30 | |
| 31 | async def test_cursor_iterable_02(self): |
| 32 | # Test that it's not possible to create a cursor without hold |
| 33 | # outside of a transaction |
| 34 | s = await self.con.prepare( |
| 35 | 'DECLARE t BINARY CURSOR WITHOUT HOLD FOR SELECT 1') |
| 36 | with self.assertRaises(asyncpg.NoActiveSQLTransactionError): |
| 37 | await s.fetch() |
| 38 | |
| 39 | # Now test that statement.cursor() does not let you |
| 40 | # iterate over it outside of a transaction |
| 41 | st = await self.con.prepare('SELECT generate_series(0, 20)') |
| 42 | |
| 43 | it = st.cursor(prefetch=5).__aiter__() |
| 44 | if inspect.isawaitable(it): |
| 45 | it = await it |
| 46 | |
| 47 | with self.assertRaisesRegex(asyncpg.NoActiveSQLTransactionError, |
| 48 | 'cursor cannot be created.*transaction'): |
| 49 | await it.__anext__() |
| 50 | |
| 51 | async def test_cursor_iterable_03(self): |
| 52 | st = await self.con.prepare('SELECT generate_series(0, 20)') |