Exemplo n.º 1
0
 def test_push(self):
     bitcache = BitCache()
     cache = "100" * 100
     with pytest.raises(TypeError):
         bitcache.push(0)
     with pytest.raises(ValueError):
         bitcache.push("abc")
     bitcache.push(cache)
     assert bitcache._cache == cache and bitcache.size == len(cache)
Exemplo n.º 2
0
 def test_state(self):
     bitcache = BitCache()
     cache = "100" * 100
     bitcache.push(cache)
     assert bitcache.state == {"size": len(cache)}
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 def test_flush(self):
     bitcache = BitCache()
     cache = "100" * 100
     bitcache.push(cache)
     bitcache.flush()
     assert bitcache.size == 0 and bitcache.dump() == ""
Exemplo n.º 5
0
 def test_dump(self):
     bitcache = BitCache()
     cache = "100" * 100
     bitcache.push(cache)
     assert bitcache.dump() == cache
Exemplo n.º 6
0
 def test_isbitstring(self):
     bitcache = BitCache()
     with pytest.raises(TypeError):
         bitcache.isbitstring(4)
     assert not bitcache.isbitstring("abc")
     assert bitcache.isbitstring("100")