def test_non_overflow(slabutil): "Test that slabs do not overflow upto the slab LRU size." slabs = [] def _mkslab(i): v = [i * _SLABSZ] return slabutil_make_slab(_NS, zip(map(str, v), v)) def _cb(self, key, slabdesc, seq=[0]): assert False lc = LRUCache(_LRUSZ, _cb) for i in xrange(_LRUSZ): sl = _mkslab(i) slabs.append(sl) lc.insert_slab(sl)
def test_overflow(slabutil): "Test that slabs overflow in LRU sequence." slabs = [] def _mkslab(i): v = [i * _SLABSZ] return slabutil_make_slab(_NS, zip(map(str, v), v)) def _cb(slabkey, slabdesc, seq=[0]): n = seq[0] assert slabdesc is slabs[n] seq[0] = n + 1 lc = LRUCache(_LRUSZ, _cb) for i in xrange(2*_LRUSZ): sl = _mkslab(i) slabs.append(sl) lc.insert_slab(sl)
def test_overflow(slabutil): "Test that slabs overflow in LRU sequence." slabs = [] def _mkslab(i): v = [i * _SLABSZ] return slabutil_make_slab(_NS, zip(map(str, v), v)) def _cb(slabkey, slabdesc, seq=[0]): n = seq[0] assert slabdesc is slabs[n] seq[0] = n + 1 lc = LRUCache(_LRUSZ, _cb) for i in xrange(2 * _LRUSZ): sl = _mkslab(i) slabs.append(sl) lc.insert_slab(sl)
def test_flush(slabutil): "Test that flush presents slabs in sequence." slabs = [] def _mkslab(i): v = [i * _SLABSZ] return slabutil_make_slab(_NS, zip(map(str, v), v)) seen = [False] def _cb(slabkey, slabdesc, seq=[0], seen=seen): seen[0] = True n = seq[0] assert slabdesc is slabs[n] seq[0] = n + 1 lc = LRUCache(_LRUSZ, _cb) for i in xrange(_LRUSZ): sl = _mkslab(i) slabs.append(sl) lc.insert_slab(sl) lc.flush() assert seen[0] is True
def test_empty(slabutil): "Test the properties of an empty cache object." lc = LRUCache(_LRUSZ) assert len(lc) == 0 assert lc.get(_NS, _KEY) is None
def pytest_funcarg__lrucache(request): "Prepare a pre-initialized cache object." return LRUCache(_LRUSZ)