Exemplo n.º 1
0
    def test_init_from_iterable(self):
        iterable = [1, 2, 3, 4, 5]
        queue = CircularQueue.from_iterable(iterable)

        assert len(queue) == len(iterable)
        assert queue[::] == iterable
        assert isinstance(queue, CircularQueue)
Exemplo n.º 2
0
    def test_copy(self):
        data = [0, 1, 2, 3]
        queue = CircularQueue.from_iterable(data)

        queue_copy = queue.copy()

        assert queue[::] == queue_copy[::]
Exemplo n.º 3
0
    def test_maxlen(self):
        desired_queue_size = 3
        data = [0, 1, 2, 3]
        queue1 = CircularQueue(desired_queue_size)
        queue2 = CircularQueue.from_iterable(data)

        assert queue1.maxlen == desired_queue_size
        assert queue2.maxlen == len(data)
Exemplo n.º 4
0
    def test_no_crc(self):
        data = [1, 2, 3, 4, 5]
        cq = CircularQueue.from_iterable(data)

        state = SerialCrcState(cq)
        state.parse()

        assert not state.is_succesful
Exemplo n.º 5
0
    def test_no_packet(self):
        data = [1, 2, 3, 4, 5]
        cq = CircularQueue.from_iterable(data)

        state = SerialStartState(cq)

        state.parse()

        assert state.find_next_state() == state
Exemplo n.º 6
0
    def test__getitem__list(self):
        data = [0, 1, 2, 3]
        queue = CircularQueue.from_iterable(data)
        with pytest.raises(TypeError):
            _ = queue[1.1::]
        with pytest.raises(TypeError):
            _ = queue[:1.1:]
        with pytest.raises(TypeError):
            _ = queue[::1.1]

        for i in range(4):
            assert queue[:i] == data[:i]

        assert queue[2:-1] == data[2:-1]
        assert queue[2:] == data[2:]
        assert queue[::-1] == data[::-1]
Exemplo n.º 7
0
    def test_overflow_packet(self):
        packet = []
        for i in range(256):
            packet.append(i)

        packet[1] = 256

        cq = CircularQueue.from_iterable(packet)
        state = SerialLenState(cq)

        with pytest.raises(PacketStateError) as err:
            state.parse()

        err_str = err.value.message
        assert (
            err_str ==
            "PACKET STATE ERROR: Packet overflow, message is bigger than 256 bytes\n"
        )
Exemplo n.º 8
0
    def test__getitem__single(self):
        data = [0, 1, 2, 3]
        queue = CircularQueue.from_iterable(data)

        with pytest.raises(IndexError):
            _ = queue[4]
        with pytest.raises(IndexError):
            _ = queue[-5]

        for i in range(4):
            assert queue[i] == data[i]

        # test for circularity
        queue.popleft()
        queue.append(11)
        queue.popleft()
        queue.append(12)
        new_data = [2, 3, 11, 12]

        for i in range(4):
            assert queue[i] == new_data[i]
Exemplo n.º 9
0
    def test__str__(self):
        data = [1, 2, 3]
        queue = CircularQueue.from_iterable(data)

        assert data.__str__() == queue.__str__()
Exemplo n.º 10
0
    def test_clear(self):
        data = [0, 1, 2, 3]
        queue = CircularQueue.from_iterable(data)

        queue.clear()
        assert len(queue) == 0
Exemplo n.º 11
0
def circular_queue_with_packet(request):
    packet = make_fake_packet(request.param)
    cq = CircularQueue.from_iterable(packet)

    return [cq, packet]