Пример #1
0
    describe "retry_gaps":
        async it "returns the retry gaps", V:
            kwargs = {"host": "192.168.0.3", "port": 56700}
            transport = await V.session.make_transport("d073d5", Services.UDP, kwargs)
            assert isinstance(transport, UDP)

            packet = mock.NonCallableMock(name="packet", spec=[])

            uro1 = V.session.retry_gaps(packet, transport)
            assert uro1 is V.transport_target.gaps

    describe "determine_needed_transport":
        async it "says udp", V:
            services = mock.NonCallableMock(name="services", spec=[])
            packets = [DeviceMessages.GetPower(), DeviceMessages.StateLabel()]

            for packet in packets:
                got = await V.session.determine_needed_transport(packet, services)
                assert got == [Services.UDP]

    describe "choose_transport":
        async it "complains if we can't determined need transport", V:
            determine_needed_transport = pytest.helpers.AsyncMock(name="determine_needed_transport")
            determine_needed_transport.return_value = []

            packet = mock.Mock(name="packet", protocol=9001, pkt_type=89)
            services = mock.Mock(name="services")

            msg = "Unable to determine what service to send packet to"
            kwargs = {"protocol": 9001, "pkt_type": 89}
Пример #2
0
        pkt.sequence = 1
        pkt.target = None
        assert e.bts == pkt.pack()

    it "can set replies", EKLS, device, io:
        e = EKLS(device, io, pkt=DeviceMessages.GetPower())
        assert not e.handled
        assert e.replies is None

        replies = [DeviceMessages.StatePower(level=0), DeviceMessages.StatePower(level=65535)]
        e.set_replies(*replies)

        assert e.handled
        assert e.replies == replies

        other = [DeviceMessages.StateLabel()]
        e.set_replies(*other)
        assert e.handled
        assert e.replies == other

    it "can add replies", EKLS, device, io:
        reply1 = DeviceMessages.StatePower()
        reply2 = DeviceMessages.StateLabel()
        reply3 = DeviceMessages.StateGroup()
        reply4 = DeviceMessages.StateLocation()
        reply5 = DeviceMessages.StateInfo()

        e = EKLS(device, io, pkt=DeviceMessages.GetPower())
        assert not e.handled
        assert e.replies is None
Пример #3
0

describe "Responders":

    describe "LightStateResponder":

        @pytest.fixture()
        async def device(self):
            device = Device(chp.LightStateResponder())
            async with device:
                device.assertAttrs(label="", power=0, color=chp.Color(0, 0, 1, 3500))
                yield device

        async it "responds to label messages", device:
            await device.assertResponse(
                DeviceMessages.GetLabel(), [DeviceMessages.StateLabel(label="")]
            )
            await device.assertResponse(
                DeviceMessages.SetLabel(label="sam"),
                [DeviceMessages.StateLabel(label="sam")],
                label="sam",
            )
            await device.assertResponse(
                DeviceMessages.GetLabel(), [DeviceMessages.StateLabel(label="sam")], label="sam"
            )

        async it "responds to power messages", device:
            await device.assertResponse(
                DeviceMessages.GetPower(), [DeviceMessages.StatePower(level=0)]
            )
            await device.assertResponse(
Пример #4
0
                        assert await outgoing(reply, make_incoming(DeviceMessages.SetPower)) == []

                    assert await outgoing(ack, request_event) == [ack]
                    assert await outgoing(reply, request_event) == []

                    assert await outgoing(ack, make_incoming(DeviceMessages.SetPower)) == [ack]
                    assert await outgoing(reply, make_incoming(DeviceMessages.SetPower)) == [reply]

                assert await outgoing(ack, request_event) == [ack]
                assert await outgoing(reply, request_event) == [reply]

            async it "can ignore replies that themselves are a particular class", make_incoming, outgoing, fltr:
                request_event = make_incoming(DeviceMessages.GetPower)
                ack = CoreMessages.Acknowledgement()
                reply1 = DeviceMessages.StatePower()
                reply2 = DeviceMessages.StateLabel()

                assert await outgoing(ack, request_event) == [ack]
                assert await outgoing(reply1, request_event) == [reply1]
                assert await outgoing(reply2, request_event) == [reply2]

                with fltr.lost_replies(DeviceMessages.StatePower):
                    assert await outgoing(ack, request_event) == [ack]
                    assert await outgoing(reply1, request_event) == []
                    assert await outgoing(reply2, request_event) == [reply2]

                    with fltr.lost_replies(DeviceMessages.StateLabel):
                        assert await outgoing(ack, request_event) == [ack]
                        assert await outgoing(reply1, request_event) == []
                        assert await outgoing(reply2, request_event) == []
Пример #5
0

describe "LightDevice":

    @pytest.fixture()
    def device(self):
        device = devices["a19"]
        devices.store(device).assertAttrs(label="", power=0, color=hp.Color(0, 0, 1, 3500))
        return device

    @pytest.fixture()
    def assertResponse(self, device, **attrs):
        return makeAssertResponse(device, **attrs)

    async it "responds to label messages", device, assertResponse:
        await assertResponse(DeviceMessages.GetLabel(), [DeviceMessages.StateLabel(label="")])
        await assertResponse(
            DeviceMessages.SetLabel(label="sam"),
            [DeviceMessages.StateLabel(label="sam")],
            label="sam",
        )
        await assertResponse(
            DeviceMessages.GetLabel(), [DeviceMessages.StateLabel(label="sam")], label="sam"
        )

    async it "responds to power messages", device, assertResponse:
        await assertResponse(DeviceMessages.GetPower(), [DeviceMessages.StatePower(level=0)])
        await assertResponse(
            DeviceMessages.SetPower(level=200), [DeviceMessages.StatePower(level=0)], power=200
        )
        await assertResponse(