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