~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transactions.py

  • Committer: Robert Collins
  • Date: 2006-03-07 12:39:38 UTC
  • mfrom: (1594 +trunk)
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060307123938-f75ff66ebcc0c4d0
Merge in bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 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
 
32
32
 
33
33
    def __init__(self, message):
34
34
        self._message = message
35
 
        self.finished = False
36
35
 
37
36
    def __eq__(self, other):
38
37
        if other is None:
39
38
            return False
40
39
        return self._message == other._message
41
40
 
42
 
    def transaction_finished(self):
43
 
        self.finished = True
44
 
 
45
41
 
46
42
class TestSymbols(TestCase):
47
43
 
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)
74
70
    def test_finish_returns(self):
75
71
        self.transaction.finish()
76
72
 
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
 
 
84
73
    def test_zero_size_cache(self):
85
74
        self.transaction.set_cache_size(0)
86
75
        weave = DummyWeave('a weave')
99
88
        # its not a weakref system
100
89
        self.assertEqual(DummyWeave("another weave"),
101
90
                         self.transaction.map.find_weave("id"))
102
 
 
 
91
        
103
92
    def test_small_cache(self):
104
93
        self.transaction.set_cache_size(1)
105
94
        # add an object, should not fall right out if there are no references
139
128
        self.assertEqual(DummyWeave('a weave'),
140
129
                         self.transaction.map.find_weave("id"))
141
130
 
142
 
    def test_writable(self):
143
 
        self.assertFalse(self.transaction.writeable())
 
131
    def test_precious_revision_history(self):
 
132
        """Disabled test until revision-history is a real object."""
 
133
        print "Disabled: test_precious_revision_history"
 
134
        return
 
135
        self.transaction.set_cache_size(0)
 
136
        history = []
 
137
        self.transaction.map.add_revision_history(history)
 
138
        self.assertEqual(history, self.transaction.map.find_revision_history())
 
139
        history = None
 
140
        # add an object, should not fall out even with no references.
 
141
        self.transaction.register_clean(
 
142
            self.transaction.map.find_revision_history(), precious=True)
 
143
        self.assertEqual([], self.transaction.map.find_revision_history())
144
144
 
145
145
 
146
146
class TestPassThroughTransaction(TestCase):
151
151
    def test_register_clean(self):
152
152
        transaction = transactions.PassThroughTransaction()
153
153
        transaction.register_clean("anobject")
154
 
 
 
154
    
155
155
    def test_register_dirty(self):
156
156
        transaction = transactions.PassThroughTransaction()
157
157
        transaction.register_dirty("anobject")
158
 
 
 
158
    
159
159
    def test_map(self):
160
160
        transaction = transactions.PassThroughTransaction()
161
161
        self.assertNotEqual(None, getattr(transaction, "map", None))
162
 
 
 
162
    
163
163
    def test_add_and_get(self):
164
164
        transaction = transactions.PassThroughTransaction()
165
165
        weave = "a weave"
166
166
        transaction.map.add_weave("id", weave)
167
167
        self.assertEqual(None, transaction.map.find_weave("id"))
168
 
 
 
168
        
169
169
    def test_finish_returns(self):
170
170
        transaction = transactions.PassThroughTransaction()
171
171
        transaction.finish()
172
172
 
173
 
    def test_finish_tells_versioned_file_finished(self):
174
 
        # pass through transactions allow writes so they
175
 
        # need to inform versioned files about finishing
176
 
        weave = DummyWeave('a weave')
177
 
        transaction = transactions.PassThroughTransaction()
178
 
        transaction.register_dirty(weave)
179
 
        transaction.finish()
180
 
        self.assertTrue(weave.finished)
181
 
 
182
173
    def test_cache_is_ignored(self):
183
174
        transaction = transactions.PassThroughTransaction()
184
175
        transaction.set_cache_size(100)
186
177
        transaction.map.add_weave("id", weave)
187
178
        self.assertEqual(None, transaction.map.find_weave("id"))
188
179
 
189
 
    def test_writable(self):
190
 
        transaction = transactions.PassThroughTransaction()
191
 
        self.assertTrue(transaction.writeable())
192
 
 
193
 
 
 
180
        
194
181
class TestWriteTransaction(TestCase):
195
182
 
196
183
    def setUp(self):
199
186
 
200
187
    def test_register_clean(self):
201
188
        self.transaction.register_clean("anobject")
202
 
 
 
189
    
203
190
    def test_register_dirty(self):
204
191
        self.transaction.register_dirty("anobject")
205
 
 
 
192
    
206
193
    def test_map(self):
207
194
        self.assertNotEqual(None, getattr(self.transaction, "map", None))
208
 
 
 
195
    
209
196
    def test_add_and_get(self):
210
197
        weave = "a weave"
211
198
        self.transaction.map.add_weave("id", weave)
212
199
        self.assertEqual(weave, self.transaction.map.find_weave("id"))
213
 
 
 
200
        
214
201
    def test_finish_returns(self):
215
202
        self.transaction.finish()
216
203
 
217
 
    def test_finish_tells_versioned_file_finished(self):
218
 
        # write transactions allow writes so they
219
 
        # need to inform versioned files about finishing
220
 
        weave = DummyWeave('a weave')
221
 
        self.transaction.register_dirty(weave)
222
 
        self.transaction.finish()
223
 
        self.assertTrue(weave.finished)
224
 
 
225
204
    def test_zero_size_cache(self):
226
205
        self.transaction.set_cache_size(0)
227
206
        # add an object, should fall right out if there are no references
250
229
        weave = None
251
230
        self.transaction.register_dirty(self.transaction.map.find_weave("id"))
252
231
        self.assertNotEqual(None, self.transaction.map.find_weave("id"))
253
 
 
 
232
    
254
233
    def test_clean_to_dirty(self):
255
234
        # a clean object may become dirty.
256
235
        weave = DummyWeave('A weave')
298
277
                                        precious=True)
299
278
        self.assertEqual(DummyWeave('a weave'),
300
279
                         self.transaction.map.find_weave("id"))
301
 
 
302
 
    def test_writable(self):
303
 
        self.assertTrue(self.transaction.writeable())