~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transactions.py

(vila) Calling super() instead of mentioning the base class in setUp avoid
 mistakes. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2009, 2011 Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
"""Tests for the behaviour of the Transaction concept in bzr."""
19
19
 
20
 
# import system imports here
21
 
import os
22
 
import sys
23
 
 
24
20
#import bzrlib specific imports here
25
21
import bzrlib.errors as errors
26
 
from bzrlib.tests import TestCase, TestCaseInTempDir
 
22
from bzrlib.tests import TestCase
27
23
import bzrlib.transactions as transactions
28
24
 
29
25
 
60
56
        self.transaction.register_clean("anobject")
61
57
 
62
58
    def test_register_dirty_raises(self):
63
 
        self.assertRaises(errors.ReadOnlyError, 
 
59
        self.assertRaises(errors.ReadOnlyError,
64
60
                          self.transaction.register_dirty,"anobject")
65
 
    
 
61
 
66
62
    def test_map(self):
67
63
        self.assertNotEqual(None, getattr(self.transaction, "map", None))
68
 
    
 
64
 
69
65
    def test_add_and_get(self):
70
66
        weave = "a weave"
71
67
        self.transaction.map.add_weave("id", weave)
99
95
        # its not a weakref system
100
96
        self.assertEqual(DummyWeave("another weave"),
101
97
                         self.transaction.map.find_weave("id"))
102
 
        
 
98
 
103
99
    def test_small_cache(self):
104
100
        self.transaction.set_cache_size(1)
105
101
        # add an object, should not fall right out if there are no references
139
135
        self.assertEqual(DummyWeave('a weave'),
140
136
                         self.transaction.map.find_weave("id"))
141
137
 
142
 
    def test_precious_revision_history(self):
143
 
        """Disabled test until revision-history is a real object."""
144
 
        print "Disabled: test_precious_revision_history"
145
 
        return
146
 
        self.transaction.set_cache_size(0)
147
 
        history = []
148
 
        self.transaction.map.add_revision_history(history)
149
 
        self.assertEqual(history, self.transaction.map.find_revision_history())
150
 
        history = None
151
 
        # add an object, should not fall out even with no references.
152
 
        self.transaction.register_clean(
153
 
            self.transaction.map.find_revision_history(), precious=True)
154
 
        self.assertEqual([], self.transaction.map.find_revision_history())
155
 
 
156
138
    def test_writable(self):
157
139
        self.assertFalse(self.transaction.writeable())
158
140
 
165
147
    def test_register_clean(self):
166
148
        transaction = transactions.PassThroughTransaction()
167
149
        transaction.register_clean("anobject")
168
 
    
 
150
 
169
151
    def test_register_dirty(self):
170
152
        transaction = transactions.PassThroughTransaction()
171
153
        transaction.register_dirty("anobject")
172
 
    
 
154
 
173
155
    def test_map(self):
174
156
        transaction = transactions.PassThroughTransaction()
175
157
        self.assertNotEqual(None, getattr(transaction, "map", None))
176
 
    
 
158
 
177
159
    def test_add_and_get(self):
178
160
        transaction = transactions.PassThroughTransaction()
179
161
        weave = "a weave"
180
162
        transaction.map.add_weave("id", weave)
181
163
        self.assertEqual(None, transaction.map.find_weave("id"))
182
 
        
 
164
 
183
165
    def test_finish_returns(self):
184
166
        transaction = transactions.PassThroughTransaction()
185
167
        transaction.finish()
203
185
    def test_writable(self):
204
186
        transaction = transactions.PassThroughTransaction()
205
187
        self.assertTrue(transaction.writeable())
206
 
        
 
188
 
207
189
 
208
190
class TestWriteTransaction(TestCase):
209
191
 
213
195
 
214
196
    def test_register_clean(self):
215
197
        self.transaction.register_clean("anobject")
216
 
    
 
198
 
217
199
    def test_register_dirty(self):
218
200
        self.transaction.register_dirty("anobject")
219
 
    
 
201
 
220
202
    def test_map(self):
221
203
        self.assertNotEqual(None, getattr(self.transaction, "map", None))
222
 
    
 
204
 
223
205
    def test_add_and_get(self):
224
206
        weave = "a weave"
225
207
        self.transaction.map.add_weave("id", weave)
226
208
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
227
 
        
 
209
 
228
210
    def test_finish_returns(self):
229
211
        self.transaction.finish()
230
212
 
264
246
        weave = None
265
247
        self.transaction.register_dirty(self.transaction.map.find_weave("id"))
266
248
        self.assertNotEqual(None, self.transaction.map.find_weave("id"))
267
 
    
 
249
 
268
250
    def test_clean_to_dirty(self):
269
251
        # a clean object may become dirty.
270
252
        weave = DummyWeave('A weave')