MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / test_cursor_02

Method test_cursor_02

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

Source from the content-addressed store, hash-verified

110 await st.cursor()
111
112 async def test_cursor_02(self):
113 st = await self.con.prepare('SELECT generate_series(0, 20)')
114 async with self.con.transaction():
115 cur = await st.cursor()
116
117 for i in range(-1, 1):
118 with self.assertRaisesRegex(asyncpg.InterfaceError,
119 'greater than zero'):
120 await cur.fetch(i)
121
122 res = await cur.fetch(2)
123 self.assertEqual(res, [(0,), (1,)])
124
125 rec = await cur.fetchrow()
126 self.assertEqual(rec, (2,))
127
128 r = repr(cur)
129 self.assertTrue(r.startswith('<asyncpg.Cursor '))
130 self.assertNotIn(' exhausted ', r)
131 self.assertIn('"SELECT generate', r)
132
133 moved = await cur.forward(5)
134 self.assertEqual(moved, 5)
135
136 rec = await cur.fetchrow()
137 self.assertEqual(rec, (8,))
138
139 res = await cur.fetch(100)
140 self.assertEqual(res, [(i,) for i in range(9, 21)])
141
142 self.assertIsNone(await cur.fetchrow())
143 self.assertEqual(await cur.fetch(5), [])
144
145 r = repr(cur)
146 self.assertTrue(r.startswith('<asyncpg.Cursor '))
147 self.assertIn(' exhausted ', r)
148 self.assertIn('"SELECT generate', r)
149
150 async def test_cursor_03(self):
151 st = await self.con.prepare('SELECT generate_series(0, 20)')

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected