(subject, trans_on_subject, execute_on_subject)
| 72 | t.create(eng) |
| 73 | |
| 74 | async def run_test(subject, trans_on_subject, execute_on_subject): |
| 75 | async with subject.begin() as trans: |
| 76 | if begin_nested: |
| 77 | if not config.requirements.savepoints.enabled: |
| 78 | config.skip_test("savepoints not enabled") |
| 79 | if execute_on_subject: |
| 80 | nested_trans = subject.begin_nested() |
| 81 | else: |
| 82 | nested_trans = trans.begin_nested() |
| 83 | |
| 84 | async with nested_trans: |
| 85 | if execute_on_subject: |
| 86 | await subject.execute(t.insert(), {"data": 10}) |
| 87 | else: |
| 88 | await trans.execute(t.insert(), {"data": 10}) |
| 89 | |
| 90 | # for nested trans, we always commit/rollback on the |
| 91 | # "nested trans" object itself. |
| 92 | # only Session(future=False) will affect savepoint |
| 93 | # transaction for session.commit/rollback |
| 94 | |
| 95 | if rollback: |
| 96 | await nested_trans.rollback() |
| 97 | else: |
| 98 | await nested_trans.commit() |
| 99 | |
| 100 | if run_second_execute: |
| 101 | with assertions.expect_raises_message( |
| 102 | exc.InvalidRequestError, |
| 103 | "Can't operate on closed transaction " |
| 104 | "inside context manager. Please complete the " |
| 105 | "context manager " |
| 106 | "before emitting further commands.", |
| 107 | ): |
| 108 | if execute_on_subject: |
| 109 | await subject.execute( |
| 110 | t.insert(), {"data": 12} |
| 111 | ) |
| 112 | else: |
| 113 | await trans.execute( |
| 114 | t.insert(), {"data": 12} |
| 115 | ) |
| 116 | |
| 117 | # outside the nested trans block, but still inside the |
| 118 | # transaction block, we can run SQL, and it will be |
| 119 | # committed |
| 120 | if execute_on_subject: |
| 121 | await subject.execute(t.insert(), {"data": 14}) |
| 122 | else: |
| 123 | await trans.execute(t.insert(), {"data": 14}) |
| 124 | |
| 125 | else: |
| 126 | if execute_on_subject: |
| 127 | await subject.execute(t.insert(), {"data": 10}) |
| 128 | else: |
| 129 | await trans.execute(t.insert(), {"data": 10}) |
| 130 | |
| 131 | if trans_on_subject: |
nothing calls this directly
no test coverage detected