~abentley/bzr/status

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lru_cache.py

  • Committer: Aaron Bentley
  • Date: 2009-05-05 18:16:33 UTC
  • mfrom: (1731.1744.1078 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1931.
  • Revision ID: aaron@aaronbentley.com-20090505181633-3qtq1skwjzed0kug
Merge bzr.dev into composite-tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
        self.failUnless('foo' in cache)
47
47
        self.failIf('bar' in cache)
48
48
 
 
49
    def test_map_None(self):
 
50
        # Make sure that we can properly map None as a key.
 
51
        cache = lru_cache.LRUCache(max_cache=10)
 
52
        self.failIf(None in cache)
 
53
        cache[None] = 1
 
54
        self.assertEqual(1, cache[None])
 
55
        cache[None] = 2
 
56
        self.assertEqual(2, cache[None])
 
57
        # Test the various code paths of __getitem__, to make sure that we can
 
58
        # handle when None is the key for the LRU and the MRU
 
59
        cache[1] = 3
 
60
        cache[None] = 1
 
61
        cache[None]
 
62
        cache[1]
 
63
        cache[None]
 
64
        self.assertEqual([None, 1], [n.key for n in cache._walk_lru()])
 
65
 
 
66
    def test_add__null_key(self):
 
67
        cache = lru_cache.LRUCache(max_cache=10)
 
68
        self.assertRaises(ValueError, cache.add, lru_cache._null_key, 1)
 
69
 
49
70
    def test_overflow(self):
50
71
        """Adding extra entries will pop out old ones."""
51
72
        cache = lru_cache.LRUCache(max_cache=1, after_cleanup_count=1)
279
300
        self.assertEqual(int(cache._max_size*0.8), cache._after_cleanup_size)
280
301
        self.assertEqual(0, cache._value_size)
281
302
 
 
303
    def test_add__null_key(self):
 
304
        cache = lru_cache.LRUSizeCache()
 
305
        self.assertRaises(ValueError, cache.add, lru_cache._null_key, 1)
 
306
 
282
307
    def test_add_tracks_size(self):
283
308
        cache = lru_cache.LRUSizeCache()
284
309
        self.assertEqual(0, cache._value_size)