def test_simple_lru_expulsion_maxsize_1_null_result(self): # a regression test for #2011 def miss_fn(k): if k == 'b': return None return short(k) self.lru = lru.LRUCache(miss_fn, 1) val = self.lru.get('a') self.check_result(val, short('a'), 0, 1) val = self.lru.get('b') self.check_result(val, None, 0, 2) del (val) # 'a' was not expelled since 'b' was None self.lru.miss_fn = long val = self.lru.get('a') self.check_result(val, short('a'), 1, 2)
def test_simple_lru_expulsion_maxsize_1(self): self.lru = lru.LRUCache(short, 1) val = self.lru.get('a') self.check_result(val, short('a'), 0, 1) val = self.lru.get('a') self.check_result(val, short('a'), 1, 1) val = self.lru.get('b') self.check_result(val, short('b'), 1, 2) del (val) gc.collect() # now try 'a' again - it should be a miss self.lru.miss_fn = long val = self.lru.get('a') self.check_result(val, long('a'), 1, 3) del (val) gc.collect() # ..and that expelled B val = self.lru.get('b') self.check_result(val, long('b'), 1, 4)
def setUp(self): lru.inv_failed = False self.lru = lru.LRUCache(short, 3)