Exemplo n.º 1
0
def test_bad_operations():
    with pytest.raises(ValueError):
        RingBuffer(0)
    r = RingBuffer()
    with pytest.raises(IndexError):
        r[1]
    with pytest.raises(IndexError):
        r[-1]
    r.append(1)
    with pytest.raises(RingBuffer.InvalidOperation):
        del r[0]
Exemplo n.º 2
0
 def __init__(self, maxlen, initialize=True):
   if not maxlen >= 1:
     raise ValueError("maxlen must be greater than 0")
   self._maxlen = maxlen
   self._values = RingBuffer(maxlen, None)
   if initialize:
     self.add(time.time(), ResourceMonitorBase.ResourceResult(0, ProcessSample.empty(), 0))
Exemplo n.º 3
0
def test_append():
    r = RingBuffer(5)
    for i in xrange(0, 5):
        r.append(i)
    assert (r[0], r[1], r[2], r[3], r[4]) == (0, 1, 2, 3, 4)
    for i in xrange(5, 10):
        r.append(i)
    assert (r[0], r[1], r[2], r[3], r[4]) == (5, 6, 7, 8, 9)
Exemplo n.º 4
0
def test_circularity():
    r = RingBuffer(3)
    r.append(1)
    r.append(2)
    r.append(3)
    assert 1 in r
    assert (r[0], r[3], r[6], r[-3]) == (1, 1, 1, 1)
    r.append(4)
    assert 1 not in r
    assert (r[0], r[3], r[6], r[-3]) == (2, 2, 2, 2)