~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: 2007-11-16 23:53:17 UTC
  • mto: This revision was merged to the branch mainline in revision 3027.
  • Revision ID: john@arbash-meinel.com-20071116235317-uymqhilped1rloqy
Implement LRUCache.get() which acts like dict.get()
so that we can return a default if the key isn't present.

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
        self.assertEqual([1, 4, 5, 3, 2], list(cache._queue))
204
204
        self.assertEqual({1:1, 2:1, 3:1, 4:1, 5:1}, cache._refcount)
205
205
 
 
206
    def test_get(self):
 
207
        cache = lru_cache.LRUCache(max_cache=5)
 
208
 
 
209
        cache.add(1, 10)
 
210
        cache.add(2, 20)
 
211
        self.assertEqual(20, cache.get(2))
 
212
        self.assertIs(None, cache.get(3))
 
213
        obj = object()
 
214
        self.assertIs(obj, cache.get(3, obj))
 
215
 
206
216
 
207
217
class TestLRUSizeCache(tests.TestCase):
208
218