async def test_on_service_prop_changed(self) -> None: # GIVEN mgr = ConnmanManagerImpl(self.bus) svc1_iface = NetConnmanServiceStub() self.bus.stub_register_interface("/svc1", "net.connman.Service", svc1_iface) await mgr.setup() self.net_connman_manager.stub_update_services( [( "/svc1", self.sample_service_props, )], [], ) await asyncio.sleep(0) class ServiceListener: def __init__(self, counter) -> None: self.counter = counter def prop_changed(self, svc: ConnmanService) -> None: self.counter.update(["changed"]) cnt: TCounter[str] = Counter() listener = ServiceListener(cnt) svcs = mgr.list_services() assert len(svcs) == 1 svc1 = svcs[0] mgr.on_service_property_changed(svc1, listener.prop_changed) # WHEN svc1_iface.stub_properties_changed({ "Strength": Variant("i", 56), "State": Variant("s", "online") }) # THEN # 2 properties have changed assert cnt["changed"] == 2 # WHEN # After listener is deleted, counter should not change (we should # not keep references to the listener and allow it to be destroyed) del listener svc1_iface.stub_properties_changed({"Strength": Variant("i", 32)}) # THEN # Changes are not registered anymore assert cnt["changed"] == 2
async def test_services_changed_incomplete_data_ignore(self) -> None: # GIVEN mgr = ConnmanManagerImpl(self.bus) svc1_iface = NetConnmanServiceStub() self.bus.stub_register_interface("/svc1", "net.connman.Service", svc1_iface) await mgr.setup() incomplete_props = { "Type": Variant("s", "Skynet"), } # WHEN self.net_connman_manager.stub_update_services( [( "/svc1", incomplete_props, )], [], ) await asyncio.sleep(0) svcs = mgr.list_services() # THEN assert len(svcs) == 0