def test_FIFO_read_multiple(): buf = Buffer() buf.write(["1", "2", "3"]) assert len(buf.data) == 3 assert buf.read(3) == ["1", "2", "3"] assert len(buf.data) == 0
def test_LIFO_read_multiple(): buf = Buffer(yield_next="newest") buf.write(["1", "2", "3"]) assert len(buf.data) == 3 assert buf.read(3) == ["3", "2", "1"] assert len(buf.data) == 0
def test_write_overflow_drop_newest(): buf = Buffer(drop_next="newest", capacity=3) buf.write(["test1", "test2", "test3"]) assert list(buf.data) == ["test1", "test2", "test3"] assert len(buf.data) == 3 buf.write(["test4"]) assert list(buf.data) == ["test1", "test2", "test4"]
def test_DPusher_run(): data = ["test1", "test2"] in_buf = Buffer() out_buf = Buffer() in_buf.write(list(data)) assert list(in_buf.data) == data assert list(out_buf.data) == [] # Retry should not be triggered retry_delay = 0.1 # cycle_delay was tested to work with values greater than 0.06 # set to 0.1 for safety margin cycle_delay = 0.1 dpusher = DeterministicPusher(in_buf, out_buf, quantity=1, retry_delay=retry_delay, cycle_delay=cycle_delay) dpusher.start() # Offset us to the halfway to the first cycle time.sleep(cycle_delay / 2) # Wait until halfway after the first cycle time.sleep(cycle_delay) assert list(in_buf.data) == ["test2"] assert list(out_buf.data) == ["test1"] # Wait until halfway past the second cycle time.sleep(cycle_delay) assert list(in_buf.data) == [] assert list(out_buf.data) == ["test1", "test2"] _reset()
def test_write_multiple_preserves_order(): buf1 = Buffer() buf1.write(["1"]) buf1.write(["2"]) buf1.write(["3"]) buf2 = Buffer() buf2.write(["1", "2", "3"]) assert list(buf1.data) == ["1", "2", "3"] assert list(buf2.data) == ["1", "2", "3"]