190
176
weave = "a weave"
191
177
transaction.map.add_weave("id", weave)
192
178
self.assertEqual(None, transaction.map.find_weave("id"))
181
class TestWriteTransaction(TestCase):
184
self.transaction = transactions.WriteTransaction()
185
super(TestWriteTransaction, self).setUp()
187
def test_register_clean(self):
188
self.transaction.register_clean("anobject")
190
def test_register_dirty(self):
191
self.transaction.register_dirty("anobject")
194
self.assertNotEqual(None, getattr(self.transaction, "map", None))
196
def test_add_and_get(self):
198
self.transaction.map.add_weave("id", weave)
199
self.assertEqual(weave, self.transaction.map.find_weave("id"))
201
def test_finish_returns(self):
202
self.transaction.finish()
204
def test_zero_size_cache(self):
205
self.transaction.set_cache_size(0)
206
# add an object, should fall right out if there are no references
207
weave = DummyWeave('a weave')
208
self.transaction.map.add_weave("id", weave)
209
self.assertEqual(weave, self.transaction.map.find_weave("id"))
211
self.transaction.register_clean(self.transaction.map.find_weave("id"))
212
self.assertEqual(None, self.transaction.map.find_weave("id"))
213
# but if we have a reference to a clean object it should stick around
214
weave = DummyWeave("another weave")
215
self.transaction.map.add_weave("id", weave)
216
self.transaction.register_clean(self.transaction.map.find_weave("id"))
217
self.assertEqual(weave, self.transaction.map.find_weave("id"))
219
# its not a weakref system
220
self.assertEqual(DummyWeave("another weave"),
221
self.transaction.map.find_weave("id"))
223
def test_zero_size_cache_dirty_objects(self):
224
self.transaction.set_cache_size(0)
225
# add a dirty object, which should not fall right out.
226
weave = DummyWeave('a weave')
227
self.transaction.map.add_weave("id", weave)
228
self.assertEqual(weave, self.transaction.map.find_weave("id"))
230
self.transaction.register_dirty(self.transaction.map.find_weave("id"))
231
self.assertNotEqual(None, self.transaction.map.find_weave("id"))
233
def test_clean_to_dirty(self):
234
# a clean object may become dirty.
235
weave = DummyWeave('A weave')
236
self.transaction.map.add_weave("id", weave)
237
self.transaction.register_clean(weave)
238
self.transaction.register_dirty(weave)
239
self.assertTrue(self.transaction.is_dirty(weave))
240
self.assertFalse(self.transaction.is_clean(weave))
242
def test_small_cache(self):
243
self.transaction.set_cache_size(1)
244
# add an object, should not fall right out if there are no references
245
#sys.getrefcounts(foo)
246
self.transaction.map.add_weave("id", DummyWeave("a weave"))
247
self.transaction.register_clean(self.transaction.map.find_weave("id"))
248
self.assertEqual(DummyWeave("a weave"),
249
self.transaction.map.find_weave("id"))
250
self.transaction.map.add_weave("id2", DummyWeave("a weave also"))
251
self.transaction.register_clean(self.transaction.map.find_weave("id2"))
253
self.assertEqual(None, self.transaction.map.find_weave("id"))
254
self.assertEqual(DummyWeave("a weave also"),
255
self.transaction.map.find_weave("id2"))
257
def test_small_cache_with_references(self):
258
# if we have a reference it should stick around
260
weave2 = "another weave"
261
self.transaction.map.add_weave("id", weave)
262
self.transaction.map.add_weave("id2", weave2)
263
self.assertEqual(weave, self.transaction.map.find_weave("id"))
264
self.assertEqual(weave2, self.transaction.map.find_weave("id2"))
266
# its not a weakref system
267
self.assertEqual("a weave", self.transaction.map.find_weave("id"))
269
def test_precious_with_zero_size_cache(self):
270
self.transaction.set_cache_size(0)
271
weave = DummyWeave('a weave')
272
self.transaction.map.add_weave("id", weave)
273
self.assertEqual(weave, self.transaction.map.find_weave("id"))
275
# add an object, should not fall out even with no references.
276
self.transaction.register_clean(self.transaction.map.find_weave("id"),
278
self.assertEqual(DummyWeave('a weave'),
279
self.transaction.map.find_weave("id"))