(self)
| 13 | class TestTransaction(tb.ConnectedTestCase): |
| 14 | |
| 15 | async def test_transaction_regular(self): |
| 16 | self.assertIsNone(self.con._top_xact) |
| 17 | self.assertFalse(self.con.is_in_transaction()) |
| 18 | tr = self.con.transaction() |
| 19 | self.assertIsNone(self.con._top_xact) |
| 20 | self.assertFalse(self.con.is_in_transaction()) |
| 21 | |
| 22 | with self.assertRaises(ZeroDivisionError): |
| 23 | async with tr as with_tr: |
| 24 | self.assertIs(self.con._top_xact, tr) |
| 25 | self.assertTrue(self.con.is_in_transaction()) |
| 26 | |
| 27 | # We don't return the transaction object from __aenter__, |
| 28 | # to make it harder for people to use '.rollback()' and |
| 29 | # '.commit()' from within an 'async with' block. |
| 30 | self.assertIsNone(with_tr) |
| 31 | |
| 32 | await self.con.execute(''' |
| 33 | CREATE TABLE mytab (a int); |
| 34 | ''') |
| 35 | |
| 36 | 1 / 0 |
| 37 | |
| 38 | self.assertIsNone(self.con._top_xact) |
| 39 | self.assertFalse(self.con.is_in_transaction()) |
| 40 | |
| 41 | with self.assertRaisesRegex(asyncpg.PostgresError, |
| 42 | '"mytab" does not exist'): |
| 43 | await self.con.prepare(''' |
| 44 | SELECT * FROM mytab |
| 45 | ''') |
| 46 | |
| 47 | async def test_transaction_nested(self): |
| 48 | self.assertIsNone(self.con._top_xact) |
nothing calls this directly
no test coverage detected