示例#1
0
    def test_send(self):
        t0 = 1000
        msg = mock.Mock()
        msg.to_bytes.return_value = "123"
        handler = mock.Mock()
        obj = IM.message.Timed(msg, handler, False, t0)

        link = mock.Mock()
        protocol = IM.Protocol(link)

        obj.send(protocol)

        last = link.mock_calls[-1]
        assert last == mock.call.write("123", 0)
示例#2
0
    def test_duplicate(self):
        link = MockSerial()
        proto = IM.Protocol(link)

        # test standard input
        flags = Msg.Flags(Msg.Flags.Type.DIRECT_ACK, False)
        addr = IM.Address('0a.12.33')
        msg_keep = Msg.InpStandard(addr, addr, flags, 0x11, 0x01)
        dupe = proto._is_duplicate(msg_keep)
        assert dupe is False

        # test dupe with different hops
        flags = Msg.Flags(Msg.Flags.Type.DIRECT_ACK,
                          False,
                          hops_left=2,
                          max_hops=2)
        addr = IM.Address('0a.12.33')
        msg = Msg.InpStandard(addr, addr, flags, 0x11, 0x01)
        dupe = proto._is_duplicate(msg)
        assert dupe is True
        assert len(proto._read_history) == 1

        # not correct message type
        msg = Msg.InpUserReset()
        dupe = proto._is_duplicate(msg)
        assert dupe is False

        # test deleting an expired message
        flags = Msg.Flags(Msg.Flags.Type.DIRECT_ACK, False)
        addr = IM.Address('0a.12.44')
        msg = Msg.InpStandard(addr, addr, flags, 0x11, 0x01)
        proto._read_history.append(msg)
        msg.expire_time = 1
        assert len(proto._read_history) == 2
        proto._remove_expired_read(time.time())
        assert len(proto._read_history) == 1
        assert proto._read_history[0] == msg_keep
示例#3
0
    def test_reads(self):
        link = MockSerial()
        IM.Protocol(link)

        link.signal_read.emit(link, bytes([0x01, 0x03, 0x04]))
        link.signal_read.emit(link, bytes([0x02, 0x03, 0x04]))
示例#4
0
def test_proto():
    link = MockSerial()
    return IM.Protocol(link)