diff --git a/test/fairness/controllers/fairness_controllers_testing.py b/test/fairness/controllers/fairness_controllers_testing.py index afec03ed5a2d8370fe5db7fe2f85d26a754f5172..41b774b20712531b5de876595a4b71b43cda7901 100644 --- a/test/fairness/controllers/fairness_controllers_testing.py +++ b/test/fairness/controllers/fairness_controllers_testing.py @@ -19,6 +19,7 @@ import asyncio import logging +import warnings from unittest import mock from typing import Any, Dict, List, Optional, Tuple, Type, Union @@ -361,7 +362,8 @@ class FairnessControllerTestSuite: Return the server and client controllers, as well as the list of output metrics dictionary returned by the executed routines. """ - with pytest.warns(): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", RuntimeWarning) _, server, clients = await self.run_finalize_fairness_setup( mock.MagicMock(), use_secagg, @@ -454,7 +456,8 @@ class FairnessControllerTestSuite: """Server-side fairness setup and round routine.""" nonlocal decrypter, netwk server = self.setup_server_controller() - with pytest.warns() as warnings_record: + with warnings.catch_warnings(): + warnings.simplefilter("ignore", RuntimeWarning) await server.setup_fairness( netwk=netwk[0], aggregator=mock.create_autospec( @@ -462,7 +465,6 @@ class FairnessControllerTestSuite: ), secagg=decrypter, ) - assert len(warnings_record) <= 1 await netwk[0].broadcast_message(FairnessQuery(round_i=0)) await server.run_fairness_round( netwk=netwk[0], diff --git a/test/fairness/controllers/test_monitor_controllers.py b/test/fairness/controllers/test_monitor_controllers.py new file mode 100644 index 0000000000000000000000000000000000000000..ea8b86ea6076db49015171e5e3d48be03d9d3159 --- /dev/null +++ b/test/fairness/controllers/test_monitor_controllers.py @@ -0,0 +1,54 @@ +# coding: utf-8 + +# Copyright 2023 Inria (Institut National de Recherche en Informatique +# et Automatique) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Unit tests for mere-monitoring fairness controllers.""" + +import os +from unittest import mock + +import pytest + +from declearn.aggregator import Aggregator +from declearn.fairness.monitor import ( + FairnessMonitorClient, + FairnessMonitorServer, +) +from declearn.test_utils import make_importable + +with make_importable(os.path.dirname(os.path.abspath(__file__))): + from fairness_controllers_testing import FairnessControllerTestSuite + + +class TestFairnessMonitorControllers(FairnessControllerTestSuite): + """Unit tests for mere-monitoring fairness controllers.""" + + server_cls = FairnessMonitorServer + client_cls = FairnessMonitorClient + + @pytest.mark.parametrize( + "use_secagg", [False, True], ids=["clrtxt", "secagg"] + ) + @pytest.mark.asyncio + async def test_finalize_fairness_setup( + self, + use_secagg: bool, + ) -> None: + aggregator = mock.create_autospec(Aggregator, instance=True) + agg_final, *_ = await self.run_finalize_fairness_setup( + aggregator, use_secagg + ) + assert agg_final is aggregator