~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lru_cache.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-24 14:28:28 UTC
  • mto: This revision was merged to the branch mainline in revision 4197.
  • Revision ID: john@arbash-meinel.com-20090324142828-69pxzmujy9mxp7ge
Review tweaks from Ian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
        # 'foo' is now most recent, so final cleanup will call it last
91
91
        cache['foo']
92
92
        cache.clear()
93
 
        self.assertEqual([('baz', '1'), ('biz', '3'), ('foo', '2')], cleanup_called)
 
93
        self.assertEqual([('baz', '1'), ('biz', '3'), ('foo', '2')],
 
94
                         cleanup_called)
94
95
 
95
96
    def test_cleanup_on_replace(self):
96
97
        """Replacing an object should cleanup the old value."""
177
178
        cache.cleanup()
178
179
        self.assertEqual(2, len(cache))
179
180
 
180
 
    def test_compact_preserves_last_access_order(self):
 
181
    def test_preserve_last_access_order(self):
181
182
        cache = lru_cache.LRUCache(max_cache=5)
182
183
 
183
184
        # Add these in order
312
313
        self.assertEqual(3, cache._value_size)
313
314
        self.assertEqual({'test':'key'}, cache.items())
314
315
 
 
316
    def test_no_add_over_size_cleanup(self):
 
317
        """If a large value is not cached, we will call cleanup right away."""
 
318
        cleanup_calls = []
 
319
        def cleanup(key, value):
 
320
            cleanup_calls.append((key, value))
 
321
 
 
322
        cache = lru_cache.LRUSizeCache(max_size=10, after_cleanup_size=5)
 
323
        self.assertEqual(0, cache._value_size)
 
324
        self.assertEqual({}, cache.items())
 
325
        cache.add('test', 'key that is too big', cleanup=cleanup)
 
326
        # key was not added
 
327
        self.assertEqual(0, cache._value_size)
 
328
        self.assertEqual({}, cache.items())
 
329
        # and cleanup was called
 
330
        self.assertEqual([('test', 'key that is too big')], cleanup_calls)
 
331
 
315
332
    def test_adding_clears_cache_based_on_size(self):
316
333
        """The cache is cleared in LRU order until small enough"""
317
334
        cache = lru_cache.LRUSizeCache(max_size=20)