59
56
self.transaction.register_clean("anobject")
61
58
def test_register_dirty_raises(self):
62
self.assertRaises(errors.ReadOnlyError,
63
self.transaction.register_dirty, "anobject")
59
self.assertRaises(errors.ReadOnlyError,
60
self.transaction.register_dirty,"anobject")
62
def test_commit_raises(self):
63
self.assertRaises(errors.CommitNotPossible, self.transaction.commit)
65
65
def test_map(self):
66
66
self.assertNotEqual(None, getattr(self.transaction, "map", None))
68
68
def test_add_and_get(self):
70
70
self.transaction.map.add_weave("id", weave)
71
71
self.assertEqual(weave, self.transaction.map.find_weave("id"))
73
def test_rollback_returns(self):
74
self.transaction.rollback()
73
76
def test_finish_returns(self):
74
77
self.transaction.finish()
76
def test_finish_does_not_tell_versioned_file_finished(self):
77
# read only transactions never write, so theres no
78
# need to inform versioned files about finishing
79
weave = DummyWeave('a weave')
80
self.transaction.finish()
81
self.assertFalse(weave.finished)
83
79
def test_zero_size_cache(self):
84
80
self.transaction.set_cache_size(0)
85
81
weave = DummyWeave('a weave')
150
157
def test_register_clean(self):
151
158
transaction = transactions.PassThroughTransaction()
152
159
transaction.register_clean("anobject")
154
161
def test_register_dirty(self):
155
162
transaction = transactions.PassThroughTransaction()
156
163
transaction.register_dirty("anobject")
165
def test_commit_nothing_returns(self):
166
transaction = transactions.PassThroughTransaction()
158
169
def test_map(self):
159
170
transaction = transactions.PassThroughTransaction()
160
171
self.assertNotEqual(None, getattr(transaction, "map", None))
162
173
def test_add_and_get(self):
163
174
transaction = transactions.PassThroughTransaction()
164
175
weave = "a weave"
165
176
transaction.map.add_weave("id", weave)
166
177
self.assertEqual(None, transaction.map.find_weave("id"))
179
def test_rollback_asserts(self):
180
transaction = transactions.PassThroughTransaction()
181
self.assertRaises(errors.AlreadyCommitted, transaction.rollback)
168
183
def test_finish_returns(self):
169
184
transaction = transactions.PassThroughTransaction()
170
185
transaction.finish()
172
def test_finish_tells_versioned_file_finished(self):
173
# pass through transactions allow writes so they
174
# need to inform versioned files about finishing
175
weave = DummyWeave('a weave')
176
transaction = transactions.PassThroughTransaction()
177
transaction.register_dirty(weave)
179
self.assertTrue(weave.finished)
181
187
def test_cache_is_ignored(self):
182
188
transaction = transactions.PassThroughTransaction()
183
189
transaction.set_cache_size(100)
184
190
weave = "a weave"
185
191
transaction.map.add_weave("id", weave)
186
192
self.assertEqual(None, transaction.map.find_weave("id"))
188
def test_writable(self):
189
transaction = transactions.PassThroughTransaction()
190
self.assertTrue(transaction.writeable())
193
class TestWriteTransaction(TestCase):
196
self.transaction = transactions.WriteTransaction()
197
super(TestWriteTransaction, self).setUp()
199
def test_register_clean(self):
200
self.transaction.register_clean("anobject")
202
def test_register_dirty(self):
203
self.transaction.register_dirty("anobject")
206
self.assertNotEqual(None, getattr(self.transaction, "map", None))
208
def test_add_and_get(self):
210
self.transaction.map.add_weave("id", weave)
211
self.assertEqual(weave, self.transaction.map.find_weave("id"))
213
def test_finish_returns(self):
214
self.transaction.finish()
216
def test_finish_tells_versioned_file_finished(self):
217
# write transactions allow writes so they
218
# need to inform versioned files about finishing
219
weave = DummyWeave('a weave')
220
self.transaction.register_dirty(weave)
221
self.transaction.finish()
222
self.assertTrue(weave.finished)
224
def test_zero_size_cache(self):
225
self.transaction.set_cache_size(0)
226
# add an object, should fall right out if there are no references
227
weave = DummyWeave('a weave')
228
self.transaction.map.add_weave("id", weave)
229
self.assertEqual(weave, self.transaction.map.find_weave("id"))
231
self.transaction.register_clean(self.transaction.map.find_weave("id"))
232
self.assertEqual(None, self.transaction.map.find_weave("id"))
233
# but if we have a reference to a clean object it should stick around
234
weave = DummyWeave("another weave")
235
self.transaction.map.add_weave("id", weave)
236
self.transaction.register_clean(self.transaction.map.find_weave("id"))
237
self.assertEqual(weave, self.transaction.map.find_weave("id"))
239
# its not a weakref system
240
self.assertEqual(DummyWeave("another weave"),
241
self.transaction.map.find_weave("id"))
243
def test_zero_size_cache_dirty_objects(self):
244
self.transaction.set_cache_size(0)
245
# add a dirty object, which should not fall right out.
246
weave = DummyWeave('a weave')
247
self.transaction.map.add_weave("id", weave)
248
self.assertEqual(weave, self.transaction.map.find_weave("id"))
250
self.transaction.register_dirty(self.transaction.map.find_weave("id"))
251
self.assertNotEqual(None, self.transaction.map.find_weave("id"))
253
def test_clean_to_dirty(self):
254
# a clean object may become dirty.
255
weave = DummyWeave('A weave')
256
self.transaction.map.add_weave("id", weave)
257
self.transaction.register_clean(weave)
258
self.transaction.register_dirty(weave)
259
self.assertTrue(self.transaction.is_dirty(weave))
260
self.assertFalse(self.transaction.is_clean(weave))
262
def test_small_cache(self):
263
self.transaction.set_cache_size(1)
264
# add an object, should not fall right out if there are no references
265
# sys.getrefcounts(foo)
266
self.transaction.map.add_weave("id", DummyWeave("a weave"))
267
self.transaction.register_clean(self.transaction.map.find_weave("id"))
268
self.assertEqual(DummyWeave("a weave"),
269
self.transaction.map.find_weave("id"))
270
self.transaction.map.add_weave("id2", DummyWeave("a weave also"))
271
self.transaction.register_clean(self.transaction.map.find_weave("id2"))
273
self.assertEqual(None, self.transaction.map.find_weave("id"))
274
self.assertEqual(DummyWeave("a weave also"),
275
self.transaction.map.find_weave("id2"))
277
def test_small_cache_with_references(self):
278
# if we have a reference it should stick around
280
weave2 = "another weave"
281
self.transaction.map.add_weave("id", weave)
282
self.transaction.map.add_weave("id2", weave2)
283
self.assertEqual(weave, self.transaction.map.find_weave("id"))
284
self.assertEqual(weave2, self.transaction.map.find_weave("id2"))
286
# its not a weakref system
287
self.assertEqual("a weave", self.transaction.map.find_weave("id"))
289
def test_precious_with_zero_size_cache(self):
290
self.transaction.set_cache_size(0)
291
weave = DummyWeave('a weave')
292
self.transaction.map.add_weave("id", weave)
293
self.assertEqual(weave, self.transaction.map.find_weave("id"))
295
# add an object, should not fall out even with no references.
296
self.transaction.register_clean(self.transaction.map.find_weave("id"),
298
self.assertEqual(DummyWeave('a weave'),
299
self.transaction.map.find_weave("id"))
301
def test_writable(self):
302
self.assertTrue(self.transaction.writeable())