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