~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transactions.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-03-09 08:50:48 UTC
  • mfrom: (1553.5.83 bzr.mbp.locks)
  • Revision ID: pqm@pqm.ubuntu.com-20060309085048-37f21fd146dabe93
[merge] LockDir integration into new formats

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2005 by 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
 
20
24
#import bzrlib specific imports here
21
25
import bzrlib.errors as errors
22
 
from bzrlib.tests import TestCase
 
26
from bzrlib.tests import TestCase, TestCaseInTempDir
23
27
import bzrlib.transactions as transactions
24
28
 
25
29
 
56
60
        self.transaction.register_clean("anobject")
57
61
 
58
62
    def test_register_dirty_raises(self):
59
 
        self.assertRaises(errors.ReadOnlyError,
 
63
        self.assertRaises(errors.ReadOnlyError, 
60
64
                          self.transaction.register_dirty,"anobject")
61
 
 
 
65
    
62
66
    def test_map(self):
63
67
        self.assertNotEqual(None, getattr(self.transaction, "map", None))
64
 
 
 
68
    
65
69
    def test_add_and_get(self):
66
70
        weave = "a weave"
67
71
        self.transaction.map.add_weave("id", weave)
95
99
        # its not a weakref system
96
100
        self.assertEqual(DummyWeave("another weave"),
97
101
                         self.transaction.map.find_weave("id"))
98
 
 
 
102
        
99
103
    def test_small_cache(self):
100
104
        self.transaction.set_cache_size(1)
101
105
        # add an object, should not fall right out if there are no references
135
139
        self.assertEqual(DummyWeave('a weave'),
136
140
                         self.transaction.map.find_weave("id"))
137
141
 
 
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
 
138
156
    def test_writable(self):
139
157
        self.assertFalse(self.transaction.writeable())
140
158
 
147
165
    def test_register_clean(self):
148
166
        transaction = transactions.PassThroughTransaction()
149
167
        transaction.register_clean("anobject")
150
 
 
 
168
    
151
169
    def test_register_dirty(self):
152
170
        transaction = transactions.PassThroughTransaction()
153
171
        transaction.register_dirty("anobject")
154
 
 
 
172
    
155
173
    def test_map(self):
156
174
        transaction = transactions.PassThroughTransaction()
157
175
        self.assertNotEqual(None, getattr(transaction, "map", None))
158
 
 
 
176
    
159
177
    def test_add_and_get(self):
160
178
        transaction = transactions.PassThroughTransaction()
161
179
        weave = "a weave"
162
180
        transaction.map.add_weave("id", weave)
163
181
        self.assertEqual(None, transaction.map.find_weave("id"))
164
 
 
 
182
        
165
183
    def test_finish_returns(self):
166
184
        transaction = transactions.PassThroughTransaction()
167
185
        transaction.finish()
185
203
    def test_writable(self):
186
204
        transaction = transactions.PassThroughTransaction()
187
205
        self.assertTrue(transaction.writeable())
188
 
 
 
206
        
189
207
 
190
208
class TestWriteTransaction(TestCase):
191
209
 
195
213
 
196
214
    def test_register_clean(self):
197
215
        self.transaction.register_clean("anobject")
198
 
 
 
216
    
199
217
    def test_register_dirty(self):
200
218
        self.transaction.register_dirty("anobject")
201
 
 
 
219
    
202
220
    def test_map(self):
203
221
        self.assertNotEqual(None, getattr(self.transaction, "map", None))
204
 
 
 
222
    
205
223
    def test_add_and_get(self):
206
224
        weave = "a weave"
207
225
        self.transaction.map.add_weave("id", weave)
208
226
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
209
 
 
 
227
        
210
228
    def test_finish_returns(self):
211
229
        self.transaction.finish()
212
230
 
246
264
        weave = None
247
265
        self.transaction.register_dirty(self.transaction.map.find_weave("id"))
248
266
        self.assertNotEqual(None, self.transaction.map.find_weave("id"))
249
 
 
 
267
    
250
268
    def test_clean_to_dirty(self):
251
269
        # a clean object may become dirty.
252
270
        weave = DummyWeave('A weave')