~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lru_cache.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-30 22:40:42 UTC
  • mfrom: (4323 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4324.
  • Revision ID: tanner@real-time.com-20090430224042-53v45axtue5bw45l
Merge 1.14.1 back to trunk

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)
138
159
 
139
160
        # We hit the max
140
161
        self.assertEqual(10, len(cache))
 
162
        self.assertEqual([11, 10, 9, 1, 8, 7, 6, 5, 4, 3],
 
163
                         [n.key for n in cache._walk_lru()])
141
164
 
142
165
    def test_cleanup_shrinks_to_after_clean_count(self):
143
166
        cache = lru_cache.LRUCache(max_cache=5, after_cleanup_count=3)
277
300
        self.assertEqual(int(cache._max_size*0.8), cache._after_cleanup_size)
278
301
        self.assertEqual(0, cache._value_size)
279
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
 
280
307
    def test_add_tracks_size(self):
281
308
        cache = lru_cache.LRUSizeCache()
282
309
        self.assertEqual(0, cache._value_size)