def test_lru(self): lru_limit = 2 cache = caches.DequeOutLRUCache(lru_limit) cache[1] = 1 cache[2] = 2 cache[3] = 3 expect(len(cache)).to(equal(2)) expect(cache[2]).to(equal(2)) expect(cache[3]).to(equal(3)) expect(cache.get(1)).to(be_none) expect(len(cache.out_deque)).to(be(1)) cache[4] = 4 expect(cache.get(2)).to(be_none) expect(len(cache.out_deque)).to(be(2))
def test_constructor_should_fail_on_bad_deques(self): testf = lambda: caches.DequeOutLRUCache(_TEST_NUM_ENTRIES, out_deque=object()) expect(testf).to(raise_error(ValueError))
def test_constructor_should_accept_deques(self): a_deque = collections.deque() c = caches.DequeOutLRUCache(_TEST_NUM_ENTRIES, out_deque=a_deque) expect(c.out_deque).to(be(a_deque))
def test_constructor_should_set_up_a_default_deque(self): c = caches.DequeOutLRUCache(_TEST_NUM_ENTRIES) expect(c.out_deque).to(be_a(collections.deque))