41
41
self.assertEqual([2], list(c.itervalues()))
42
42
self.assertEqual({1: 2}, c)
44
def test_cache_size(self):
45
c = fifo_cache.FIFOCache()
46
self.assertEqual(100, c.cache_size())
48
self.assertEqual(20, c.cache_size())
44
50
def test_missing(self):
45
51
c = fifo_cache.FIFOCache()
46
52
self.assertRaises(KeyError, c.__getitem__, 1)
114
120
c = fifo_cache.FIFOCache()
115
121
self.assertRaises(NotImplementedError, c.popitem)
123
def test_resize_smaller(self):
124
c = fifo_cache.FIFOCache()
130
# No cleanup, because it is the exact size
132
self.assertEqual({1: 2, 2: 3, 3: 4, 4: 5, 5: 6}, c)
133
self.assertEqual(5, c.cache_size())
134
# Adding one more will trigger a cleanup, though
136
self.assertEqual({3: 4, 4: 5, 5: 6, 6: 7}, c)
138
self.assertEqual({5: 6, 6: 7}, c)
140
def test_resize_larger(self):
141
c = fifo_cache.FIFOCache(5, 4)
147
# No cleanup, because it is the exact size
149
self.assertEqual({1: 2, 2: 3, 3: 4, 4: 5, 5: 6}, c)
150
self.assertEqual(10, c.cache_size())
156
self.assertEqual({1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9,
159
self.assertEqual({4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10, 10: 11,
117
162
def test_setdefault(self):
118
163
c = fifo_cache.FIFOCache(5, 4)
208
253
self.assertEqual(['2'], c.values())
209
254
self.assertEqual(['2'], list(c.itervalues()))
210
255
self.assertEqual({1: '2'}, c)
256
self.assertEqual(1024*1024, c.cache_size())
212
258
def test_missing(self):
213
259
c = fifo_cache.FIFOSizeCache()
248
294
c[1] = 'abcdefgh'
249
295
self.assertEqual({}, c)
250
296
self.assertEqual(0, c._value_size)
298
def test_resize_smaller(self):
299
c = fifo_cache.FIFOSizeCache(20, 16)
304
# No cleanup, because it is the exact size
306
self.assertEqual({1: 'a', 2: 'bc', 3: 'def', 4: 'ghij'}, c)
307
self.assertEqual(10, c.cache_size())
308
# Adding one more will trigger a cleanup, though
310
self.assertEqual({3: 'def', 4: 'ghij', 5: 'k'}, c)
312
self.assertEqual({5: 'k'}, c)
314
def test_resize_larger(self):
315
c = fifo_cache.FIFOSizeCache(10, 8)
321
self.assertEqual({1: 'a', 2: 'bc', 3: 'def', 4: 'ghij'}, c)
323
self.assertEqual({1: 'a', 2: 'bc', 3: 'def', 4: 'ghij', 5: 'kl'}, c)
325
self.assertEqual({4: 'ghij', 5: 'kl', 6: 'mn'}, c)