1import unittest 2 3from mako.util import LRUCache 4 5 6class item: 7 def __init__(self, id_): 8 self.id = id_ 9 10 def __str__(self): 11 return "item id %d" % self.id 12 13 14class LRUTest(unittest.TestCase): 15 def testlru(self): 16 l = LRUCache(10, threshold=0.2) 17 18 for id_ in range(1, 20): 19 l[id_] = item(id_) 20 21 # first couple of items should be gone 22 assert 1 not in l 23 assert 2 not in l 24 25 # next batch over the threshold of 10 should be present 26 for id_ in range(11, 20): 27 assert id_ in l 28 29 l[12] 30 l[15] 31 l[23] = item(23) 32 l[24] = item(24) 33 l[25] = item(25) 34 l[26] = item(26) 35 l[27] = item(27) 36 37 assert 11 not in l 38 assert 13 not in l 39 40 for id_ in (25, 24, 23, 14, 12, 19, 18, 17, 16, 15): 41 assert id_ in l 42