MCPcopy
hub / github.com/MagicStack/asyncpg / test_pool_11

Method test_pool_11

tests/test_pool.py:233–288  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

231 await pool.close()
232
233 async def test_pool_11(self):
234 pool = await self.create_pool(database='postgres',
235 min_size=1, max_size=1)
236
237 async with pool.acquire() as con:
238 self.assertIn(repr(con._con), repr(con)) # Test __repr__.
239
240 ps = await con.prepare('SELECT 1')
241 txn = con.transaction()
242 async with con.transaction():
243 cur = await con.cursor('SELECT 1')
244 ps_cur = await ps.cursor()
245
246 self.assertIn('[released]', repr(con))
247
248 with self.assertRaisesRegex(
249 asyncpg.InterfaceError,
250 r'cannot call Connection\.execute.*released back to the pool'):
251
252 con.execute('select 1')
253
254 for meth in ('fetchval', 'fetchrow', 'fetch', 'explain',
255 'get_query', 'get_statusmsg', 'get_parameters',
256 'get_attributes'):
257 with self.assertRaisesRegex(
258 asyncpg.InterfaceError,
259 r'cannot call PreparedStatement\.{meth}.*released '
260 r'back to the pool'.format(meth=meth)):
261
262 getattr(ps, meth)()
263
264 for c in (cur, ps_cur):
265 for meth in ('fetch', 'fetchrow'):
266 with self.assertRaisesRegex(
267 asyncpg.InterfaceError,
268 r'cannot call Cursor\.{meth}.*released '
269 r'back to the pool'.format(meth=meth)):
270
271 getattr(c, meth)()
272
273 with self.assertRaisesRegex(
274 asyncpg.InterfaceError,
275 r'cannot call Cursor\.forward.*released '
276 r'back to the pool'):
277
278 c.forward(1)
279
280 for meth in ('start', 'commit', 'rollback'):
281 with self.assertRaisesRegex(
282 asyncpg.InterfaceError,
283 r'cannot call Transaction\.{meth}.*released '
284 r'back to the pool'.format(meth=meth)):
285
286 getattr(txn, meth)()
287
288 await pool.close()
289
290 async def test_pool_12(self):

Callers

nothing calls this directly

Calls 8

prepareMethod · 0.80
transactionMethod · 0.80
forwardMethod · 0.80
create_poolMethod · 0.45
acquireMethod · 0.45
cursorMethod · 0.45
executeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected