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

Method test_isolation_level

tests/test_transaction.py:183–212  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

181 self.assertFalse(self.con.is_in_transaction())
182
183 async def test_isolation_level(self):
184 await self.con.reset()
185 default_isolation = await self.con.fetchval(
186 'SHOW default_transaction_isolation'
187 )
188 isolation_levels = {
189 None: default_isolation,
190 'read_committed': 'read committed',
191 'read_uncommitted': 'read uncommitted',
192 'repeatable_read': 'repeatable read',
193 'serializable': 'serializable',
194 }
195 set_sql = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '
196 get_sql = 'SHOW TRANSACTION ISOLATION LEVEL'
197 for tx_level in isolation_levels:
198 for conn_level in isolation_levels:
199 with self.subTest(conn=conn_level, tx=tx_level):
200 if conn_level:
201 await self.con.execute(
202 set_sql + isolation_levels[conn_level]
203 )
204 level = await self.con.fetchval(get_sql)
205 self.assertEqual(level, isolation_levels[conn_level])
206 async with self.con.transaction(isolation=tx_level):
207 level = await self.con.fetchval(get_sql)
208 self.assertEqual(
209 level,
210 isolation_levels[tx_level or conn_level],
211 )
212 await self.con.reset()
213
214 async def test_nested_isolation_level(self):
215 set_sql = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '

Callers

nothing calls this directly

Calls 4

transactionMethod · 0.80
resetMethod · 0.45
fetchvalMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected