From 0040863a031e663e51523f79f5af20a2f146eb7d Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Sun, 12 Oct 2025 09:12:57 +0800 Subject: [PATCH] feat(tests): introduce ROUTE_CALLS_KEY for organizing route calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addressed the aiohttp warnings by aligning the test scaffolding with current best practices. Added an AppKey constant and stored the route tracking list through it to satisfy aiohttp’s NotAppKeyWarning expectations. Swapped the websocket lambdas for async no-op handlers so the registered routes now point to coroutine callables, clearing the deprecation warning about bare functions. --- tests/standalone/test_standalone_server.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/standalone/test_standalone_server.py b/tests/standalone/test_standalone_server.py index 2b0c55ec..095cd8aa 100644 --- a/tests/standalone/test_standalone_server.py +++ b/tests/standalone/test_standalone_server.py @@ -13,6 +13,9 @@ from aiohttp import web from py.utils.settings_paths import ensure_settings_file +ROUTE_CALLS_KEY: web.AppKey[List[Tuple[str, dict]]] = web.AppKey("route_calls") + + @pytest.fixture def standalone_module(monkeypatch) -> ModuleType: """Load the ``standalone`` module with a lightweight ``LoraManager`` stub.""" @@ -106,7 +109,7 @@ def test_standalone_lora_manager_registers_routes(monkeypatch, tmp_path, standal app = web.Application() route_calls: List[Tuple[str, dict]] = [] - app["route_calls"] = route_calls + app[ROUTE_CALLS_KEY] = route_calls locales_dir = tmp_path / "locales" locales_dir.mkdir() @@ -180,10 +183,13 @@ def test_standalone_lora_manager_registers_routes(monkeypatch, tmp_path, standal monkeypatch.setattr("py.routes.preview_routes.PreviewRoutes", DummyPreviewRoutes) monkeypatch.setattr("py.routes.stats_routes.StatsRoutes", DummyStatsRoutes) + async def _noop_ws_handler(request): + return web.Response(status=204) + ws_manager_stub = SimpleNamespace( - handle_connection=lambda request: None, - handle_download_connection=lambda request: None, - handle_init_connection=lambda request: None, + handle_connection=_noop_ws_handler, + handle_download_connection=_noop_ws_handler, + handle_init_connection=_noop_ws_handler, ) monkeypatch.setattr("py.services.websocket_manager.ws_manager", ws_manager_stub)