MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / test_cursor_02

Method test_cursor_02

tests/test_cursor.py:123–159  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

121 await self.con.execute('ROLLBACK')
122
123 async def test_cursor_02(self):
124 st = await self.con.prepare('SELECT generate_series(0, 20)')
125 async with self.con.transaction():
126 cur = await st.cursor()
127
128 for i in range(-1, 1):
129 with self.assertRaisesRegex(asyncpg.InterfaceError,
130 'greater than zero'):
131 await cur.fetch(i)
132
133 res = await cur.fetch(2)
134 self.assertEqual(res, [(0,), (1,)])
135
136 rec = await cur.fetchrow()
137 self.assertEqual(rec, (2,))
138
139 r = repr(cur)
140 self.assertTrue(r.startswith('<asyncpg.Cursor '))
141 self.assertNotIn(' exhausted ', r)
142 self.assertIn('"SELECT generate', r)
143
144 moved = await cur.forward(5)
145 self.assertEqual(moved, 5)
146
147 rec = await cur.fetchrow()
148 self.assertEqual(rec, (8,))
149
150 res = await cur.fetch(100)
151 self.assertEqual(res, [(i,) for i in range(9, 21)])
152
153 self.assertIsNone(await cur.fetchrow())
154 self.assertEqual(await cur.fetch(5), [])
155
156 r = repr(cur)
157 self.assertTrue(r.startswith('<asyncpg.Cursor '))
158 self.assertIn(' exhausted ', r)
159 self.assertIn('"SELECT generate', r)
160
161 async def test_cursor_03(self):
162 st = await self.con.prepare('SELECT generate_series(0, 20)')

Callers

nothing calls this directly

Calls 6

transactionMethod · 0.80
forwardMethod · 0.80
prepareMethod · 0.45
cursorMethod · 0.45
fetchMethod · 0.45
fetchrowMethod · 0.45

Tested by

no test coverage detected