~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transactions.py

Add finished() notifications to transactions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
    def __init__(self, message):
34
34
        self._message = message
 
35
        self.finished = False
35
36
 
36
37
    def __eq__(self, other):
37
38
        if other is None:
38
39
            return False
39
40
        return self._message == other._message
40
41
 
 
42
    def transaction_finished(self):
 
43
        self.finished = True
 
44
 
41
45
 
42
46
class TestSymbols(TestCase):
43
47
 
70
74
    def test_finish_returns(self):
71
75
        self.transaction.finish()
72
76
 
 
77
    def test_finish_does_not_tell_versioned_file_finished(self):
 
78
        # read only transactions never write, so theres no
 
79
        # need to inform versioned files about finishing
 
80
        weave = DummyWeave('a weave')
 
81
        self.transaction.finish()
 
82
        self.assertFalse(weave.finished)
 
83
 
73
84
    def test_zero_size_cache(self):
74
85
        self.transaction.set_cache_size(0)
75
86
        weave = DummyWeave('a weave')
142
153
            self.transaction.map.find_revision_history(), precious=True)
143
154
        self.assertEqual([], self.transaction.map.find_revision_history())
144
155
 
 
156
    def test_writable(self):
 
157
        self.assertFalse(self.transaction.writeable())
 
158
 
145
159
 
146
160
class TestPassThroughTransaction(TestCase):
147
161
 
170
184
        transaction = transactions.PassThroughTransaction()
171
185
        transaction.finish()
172
186
 
 
187
    def test_finish_tells_versioned_file_finished(self):
 
188
        # pass through transactions allow writes so they
 
189
        # need to inform versioned files about finishing
 
190
        weave = DummyWeave('a weave')
 
191
        transaction = transactions.PassThroughTransaction()
 
192
        transaction.register_dirty(weave)
 
193
        transaction.finish()
 
194
        self.assertTrue(weave.finished)
 
195
 
173
196
    def test_cache_is_ignored(self):
174
197
        transaction = transactions.PassThroughTransaction()
175
198
        transaction.set_cache_size(100)
177
200
        transaction.map.add_weave("id", weave)
178
201
        self.assertEqual(None, transaction.map.find_weave("id"))
179
202
 
 
203
    def test_writable(self):
 
204
        transaction = transactions.PassThroughTransaction()
 
205
        self.assertTrue(transaction.writeable())
180
206
        
 
207
 
181
208
class TestWriteTransaction(TestCase):
182
209
 
183
210
    def setUp(self):
201
228
    def test_finish_returns(self):
202
229
        self.transaction.finish()
203
230
 
 
231
    def test_finish_tells_versioned_file_finished(self):
 
232
        # write transactions allow writes so they
 
233
        # need to inform versioned files about finishing
 
234
        weave = DummyWeave('a weave')
 
235
        self.transaction.register_dirty(weave)
 
236
        self.transaction.finish()
 
237
        self.assertTrue(weave.finished)
 
238
 
204
239
    def test_zero_size_cache(self):
205
240
        self.transaction.set_cache_size(0)
206
241
        # add an object, should fall right out if there are no references
277
312
                                        precious=True)
278
313
        self.assertEqual(DummyWeave('a weave'),
279
314
                         self.transaction.map.find_weave("id"))
 
315
 
 
316
    def test_writable(self):
 
317
        self.assertTrue(self.transaction.writeable())