Merge lp:~free.ekanayaka/storm/fake-transaction into lp:storm

Proposed by Free Ekanayaka
Status: Merged
Merged at revision: 545
Proposed branch: lp:~free.ekanayaka/storm/fake-transaction
Merge into: lp:storm
Diff against target: 83 lines (+22/-11)
3 files modified
NEWS (+4/-0)
storm/twisted/testing.py (+13/-6)
storm/twisted/transact.py (+5/-5)
To merge this branch: bzr merge lp:~free.ekanayaka/storm/fake-transaction
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+109133@code.launchpad.net

Description of the change

This branch changes the FakeTransactor to use a fake transaction by default, as in most tests a real commit is not needed. It's possible to pass the real Zope transaction manager (or anther one) with the "transaction" parameter.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2012-03-30 08:28:46 +0000
3+++ NEWS 2012-06-07 13:00:27 +0000
4@@ -38,6 +38,10 @@
5 will keep the same behavior on Postgres < 9 as it's equivalent to
6 SERIALIZABLE, but it will be less strict on Postgres >= 9.
7
8+- The store.twisted.testing.FakeTransactor test helper now uses a fake
9+ transaction by default, so tests won't perform real commits as it's
10+ not generally needed.
11+
12 Bug fixes
13 ---------
14
15
16=== modified file 'storm/twisted/testing.py'
17--- storm/twisted/testing.py 2011-11-30 14:16:50 +0000
18+++ storm/twisted/testing.py 2012-06-07 13:00:27 +0000
19@@ -1,5 +1,3 @@
20-import transaction
21-
22 from twisted.python.failure import Failure
23 from twisted.internet.defer import execute
24
25@@ -23,6 +21,15 @@
26 onResult(success, result)
27
28
29+class FakeTransaction(object):
30+
31+ def commit(self):
32+ pass
33+
34+ def abort(self):
35+ pass
36+
37+
38 class FakeTransactor(Transactor):
39 """
40 A fake C{Transactor} wrapper that runs the given function in the main
41@@ -37,10 +44,10 @@
42
43 sleep = lambda *args, **kwargs: None
44
45- def __init__(self, _transaction=None):
46- if _transaction is None:
47- _transaction = transaction
48- self._transaction = _transaction
49+ def __init__(self, transaction=None):
50+ if transaction is None:
51+ transaction = FakeTransaction()
52+ self._transaction = transaction
53
54 def run(self, function, *args, **kwargs):
55 deferred = execute(self._wrap, function, *args, **kwargs)
56
57=== modified file 'storm/twisted/transact.py'
58--- storm/twisted/transact.py 2011-12-07 10:39:57 +0000
59+++ storm/twisted/transact.py 2012-06-07 13:00:27 +0000
60@@ -1,6 +1,6 @@
61 import time
62 import random
63-import transaction
64+import transaction as zope_transaction
65
66 from functools import wraps
67
68@@ -45,11 +45,11 @@
69 sleep = time.sleep
70 uniform = random.uniform
71
72- def __init__(self, threadpool, _transaction=None):
73+ def __init__(self, threadpool, transaction=None):
74 self._threadpool = threadpool
75- if _transaction is None:
76- _transaction = transaction
77- self._transaction = _transaction
78+ if transaction is None:
79+ transaction = zope_transaction
80+ self._transaction = transaction
81
82 def run(self, function, *args, **kwargs):
83 """Run C{function} in a thread.

Subscribers

People subscribed via source and target branches

to status/vote changes: