def test_push(self): bitcache = BitCache() cache = "100" * 100 with pytest.raises(TypeError): bitcache.push(0) with pytest.raises(ValueError): bitcache.push("abc") assert (bitcache.push(cache) and bitcache._cache == cache and bitcache.size == len(cache))
def test_pop(self): bitcache = BitCache() cache = "100" * 100 bitcache.push(cache) with pytest.raises(ValueError): bitcache.pop(0) with pytest.raises(ValueError): bitcache.pop(-1) with pytest.raises(RuntimeError): bitcache.pop(len(cache) + 1) assert (bitcache.pop(3) == "100" and bitcache._cache == cache[3:] and bitcache.size == len(cache) - 3) assert (bitcache.pop(len(cache) - 3) == cache[3:] and bitcache._cache == "" and bitcache.size == 0)
def test_state(self): bitcache = BitCache() cache = "100" * 100 bitcache.push(cache) assert bitcache.state == {"size": len(cache)}
def test_flush(self): bitcache = BitCache() cache = "100" * 100 bitcache.push(cache) bitcache.flush() assert bitcache.size == 0 and bitcache.dump() == ""
def test_dump(self): bitcache = BitCache() cache = "100" * 100 bitcache.push(cache) assert bitcache.dump() == cache