def properties_res_to_proto(res: typing.PropertiesRes) -> ClientMessage.PropertiesRes: """Serialize flower.PropertiesIns to ProtoBuf message.""" properties_msg = properties_to_proto(res.properties) return ClientMessage.PropertiesRes(properties=properties_msg)
import flwr from flwr.common.typing import Config from flwr.proto.transport_pb2 import ClientMessage, Parameters, Scalar from flwr.server.grpc_server.grpc_client_proxy import GrpcClientProxy MESSAGE_PARAMETERS = Parameters(tensors=[], tensor_type="np") MESSAGE_FIT_RES = ClientMessage(fit_res=ClientMessage.FitRes( parameters=MESSAGE_PARAMETERS, num_examples=10, num_examples_ceil=16, fit_duration=12.3, )) CLIENT_PROPERTIES = {"tensor_type": Scalar(string="numpy.ndarray")} MESSAGE_PROPERTIES_RES = ClientMessage( properties_res=ClientMessage.PropertiesRes(properties=CLIENT_PROPERTIES)) class GrpcClientProxyTestCase(unittest.TestCase): """Tests for GrpcClientProxy.""" def setUp(self) -> None: """Setup mocks for tests.""" self.bridge_mock = MagicMock() # Set return_value for usually blocking get_client_message method self.bridge_mock.request.return_value = MESSAGE_FIT_RES # Set return_value for get_properties self.bridge_mock_get_proprieties = MagicMock() self.bridge_mock_get_proprieties.request.return_value = MESSAGE_PROPERTIES_RES def test_get_parameters(self) -> None: """This test is currently quite simple and should be improved."""