10315.2.2
by Jeroen Vermeulen
Avoid a bunch of commits. Introducing FakeTransaction. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Fake transaction manager."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
__all__ = ['FakeTransaction'] |
|
8 |
||
9 |
||
10 |
class FakeTransaction: |
|
10315.2.4
by Jeroen Vermeulen
Replace all "Fake" and "Mock" transaction managers I can find with one implementation. |
11 |
"""Fake transaction manager.
|
12 |
||
13 |
Use this instead of `transaction` (or the old Zopeless transaction
|
|
14 |
manager) in tests if you don't really want to commit anything.
|
|
15 |
||
10315.2.5
by Jeroen Vermeulen
Lint. |
16 |
Set `log_calls` to True to enable printing of commits and aborts.
|
10315.2.4
by Jeroen Vermeulen
Replace all "Fake" and "Mock" transaction managers I can find with one implementation. |
17 |
"""
|
11168.3.1
by Jeroen Vermeulen
Test cruft and lint in Soyuz. |
18 |
commit_count = 0 |
19 |
||
10315.2.4
by Jeroen Vermeulen
Replace all "Fake" and "Mock" transaction managers I can find with one implementation. |
20 |
def __init__(self, log_calls=False): |
21 |
self.log_calls = log_calls |
|
22 |
||
23 |
def _log(self, call): |
|
24 |
"""Print calls that are being made, if desired."""
|
|
25 |
if self.log_calls: |
|
26 |
print call |
|
27 |
||
10315.2.2
by Jeroen Vermeulen
Avoid a bunch of commits. Introducing FakeTransaction. |
28 |
def begin(self): |
10315.2.4
by Jeroen Vermeulen
Replace all "Fake" and "Mock" transaction managers I can find with one implementation. |
29 |
"""Pretend to begin a transaction. Does not log."""
|
30 |
||
10315.2.2
by Jeroen Vermeulen
Avoid a bunch of commits. Introducing FakeTransaction. |
31 |
def commit(self): |
10315.2.4
by Jeroen Vermeulen
Replace all "Fake" and "Mock" transaction managers I can find with one implementation. |
32 |
"""Pretend to commit."""
|
11168.3.1
by Jeroen Vermeulen
Test cruft and lint in Soyuz. |
33 |
self.commit_count += 1 |
10315.2.4
by Jeroen Vermeulen
Replace all "Fake" and "Mock" transaction managers I can find with one implementation. |
34 |
self._log("COMMIT") |
35 |
||
10315.2.2
by Jeroen Vermeulen
Avoid a bunch of commits. Introducing FakeTransaction. |
36 |
def abort(self): |
10315.2.4
by Jeroen Vermeulen
Replace all "Fake" and "Mock" transaction managers I can find with one implementation. |
37 |
"""Pretend to roll back."""
|
38 |
self._log("ABORT") |