(self)
| 45 | ''') |
| 46 | |
| 47 | async def test_transaction_nested(self): |
| 48 | self.assertIsNone(self.con._top_xact) |
| 49 | self.assertFalse(self.con.is_in_transaction()) |
| 50 | |
| 51 | tr = self.con.transaction() |
| 52 | |
| 53 | self.assertIsNone(self.con._top_xact) |
| 54 | self.assertFalse(self.con.is_in_transaction()) |
| 55 | |
| 56 | with self.assertRaises(ZeroDivisionError): |
| 57 | async with tr: |
| 58 | self.assertIs(self.con._top_xact, tr) |
| 59 | self.assertTrue(self.con.is_in_transaction()) |
| 60 | |
| 61 | await self.con.execute(''' |
| 62 | CREATE TABLE mytab (a int); |
| 63 | ''') |
| 64 | |
| 65 | async with self.con.transaction(): |
| 66 | self.assertIs(self.con._top_xact, tr) |
| 67 | self.assertTrue(self.con.is_in_transaction()) |
| 68 | |
| 69 | await self.con.execute(''' |
| 70 | INSERT INTO mytab (a) VALUES (1), (2); |
| 71 | ''') |
| 72 | |
| 73 | self.assertIs(self.con._top_xact, tr) |
| 74 | self.assertTrue(self.con.is_in_transaction()) |
| 75 | |
| 76 | with self.assertRaises(ZeroDivisionError): |
| 77 | in_tr = self.con.transaction() |
| 78 | async with in_tr: |
| 79 | |
| 80 | self.assertIs(self.con._top_xact, tr) |
| 81 | self.assertTrue(self.con.is_in_transaction()) |
| 82 | |
| 83 | await self.con.execute(''' |
| 84 | INSERT INTO mytab (a) VALUES (3), (4); |
| 85 | ''') |
| 86 | |
| 87 | 1 / 0 |
| 88 | |
| 89 | st = await self.con.prepare('SELECT * FROM mytab;') |
| 90 | |
| 91 | recs = [] |
| 92 | async for rec in st.cursor(): |
| 93 | recs.append(rec) |
| 94 | |
| 95 | self.assertEqual(len(recs), 2) |
| 96 | self.assertEqual(recs[0][0], 1) |
| 97 | self.assertEqual(recs[1][0], 2) |
| 98 | |
| 99 | self.assertIs(self.con._top_xact, tr) |
| 100 | self.assertTrue(self.con.is_in_transaction()) |
| 101 | |
| 102 | 1 / 0 |
| 103 | |
| 104 | self.assertIs(self.con._top_xact, None) |
nothing calls this directly
no test coverage detected