await runner.per_test() describe "Repeater": async it "can find all serials", runner: async with runner.target.session() as sender: for ref in ("", "_", None, sb.NotSpecified, FoundSerials()): assert await find_serials(ref, sender, timeout=1) == (runner.serials, []) async it "can find a specific serial", runner: async with runner.target.session() as sender: assert await find_serials(light1.serial, sender, timeout=1) == ([light1.serial], []) async with runner.target.session() as sender: with light1.offline(): assert await find_serials(light1.serial, sender, timeout=0.5) == ( [], [light1.serial], ) async it "can find a number of serials", runner: for ref in (f"{light1.serial},{light2.serial}", [light1.serial, light2.serial]): async with runner.target.session() as sender: assert await find_serials(ref, sender, timeout=1) == ( [light1.serial, light2.serial], [], ) with light1.offline(): async with runner.target.session() as sender:
async def gen(serial, sender, **kwargs): assert serial in (light1.serial, light2.serial) yield Pipeline([DeviceMessages.GetPower(), DeviceMessages.SetLabel(label="wat")]) msg = FromGeneratorPerSerial(gen) expected = { light1: [DeviceMessages.GetPower(), DeviceMessages.SetLabel(label="wat")], light2: [DeviceMessages.GetPower(), DeviceMessages.SetLabel(label="wat")], light3: [], } errors = [] got = defaultdict(list) with light3.offline(): async for pkt in runner.sender(msg, runner.serials, error_catcher=errors): got[pkt.serial].append(pkt) assert len(runner.devices) > 0 for device in runner.devices: if device not in expected: assert False, f"No expectation for {device.serial}" device.compare_received(expected[device]) if expected[device]: assert len(got[device.serial]) == 2 assert got[device.serial][0] | DeviceMessages.StatePower assert got[device.serial][1] | DeviceMessages.StateLabel
error_catcher=errors, message_timeout=0.1, find_timeout=0.1, ) assert got == { light1.serial: (True, {"presence": True, "label": "bob"}), light2.serial: (False, {"presence": True}), } async it "fires for offline devices that have already been discovered", runner: errors = [] _, serials = await FoundSerials().find(runner.sender, timeout=1) assert all(serial in serials for serial in two_lights) with light2.offline(): got = await self.gather( runner, two_lights, "presence", "label", error_catcher=errors, message_timeout=0.1, find_timeout=0.1, ) assert got == { light1.serial: (True, {"presence": True, "label": "bob"}), light2.serial: (False, {"presence": True}), }