From 28f136487484c0efc0987fcd88170deff32381d2 Mon Sep 17 00:00:00 2001 From: Sergey Borisov Date: Tue, 7 Apr 2026 09:39:18 +0200 Subject: [PATCH] fix: remove dead code from test_middleware_with_agent.py --- python/packages/a2a/tests/test_a2a_agent.py | 22 +++++-------- .../tests/core/test_middleware_with_agent.py | 33 ++++++++----------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/python/packages/a2a/tests/test_a2a_agent.py b/python/packages/a2a/tests/test_a2a_agent.py index a0919cbda4..442960a7ee 100644 --- a/python/packages/a2a/tests/test_a2a_agent.py +++ b/python/packages/a2a/tests/test_a2a_agent.py @@ -1284,13 +1284,11 @@ async def test_streaming_artifact_update_event_does_not_duplicate_terminal_task_ final=True, ) - mock_a2a_client.responses.extend( - [ - (working_task, first_chunk), - (working_task, second_chunk), - (terminal_task, terminal_event), - ] - ) + mock_a2a_client.responses.extend([ + (working_task, first_chunk), + (working_task, second_chunk), + (terminal_task, terminal_event), + ]) stream = a2a_agent.run("Hello", stream=True) updates: list[AgentResponseUpdate] = [] @@ -1371,12 +1369,10 @@ async def test_streaming_terminal_task_only_emits_unstreamed_artifacts( final=True, ) - mock_a2a_client.responses.extend( - [ - (working_task, streamed_chunk), - (terminal_task, terminal_event), - ] - ) + mock_a2a_client.responses.extend([ + (working_task, streamed_chunk), + (terminal_task, terminal_event), + ]) stream = a2a_agent.run("Hello", stream=True) updates: list[AgentResponseUpdate] = [] diff --git a/python/packages/core/tests/core/test_middleware_with_agent.py b/python/packages/core/tests/core/test_middleware_with_agent.py index 9f56768770..900c72108f 100644 --- a/python/packages/core/tests/core/test_middleware_with_agent.py +++ b/python/packages/core/tests/core/test_middleware_with_agent.py @@ -1467,17 +1467,15 @@ async def test_decorator_and_type_mismatch(self, client: MockChatClient) -> None # This will cause a type error at decoration time, so we need to test differently # Should raise MiddlewareException due to mismatch during agent creation - with pytest.raises(MiddlewareException, match="MiddlewareTypes type mismatch"): - - @agent_middleware # type: ignore[arg-type] - async def mismatched_middleware( - context: FunctionInvocationContext, # Wrong type for @agent_middleware - call_next: Any, - ) -> None: - await call_next() + @agent_middleware # type: ignore[arg-type] + async def mismatched_middleware( + context: FunctionInvocationContext, # Wrong type for @agent_middleware + call_next: Any, + ) -> None: + await call_next() - agent = Agent(client=client, middleware=[mismatched_middleware]) - await agent.run([Message(role="user", contents=["test"])]) + with pytest.raises(MiddlewareException, match="MiddlewareTypes type mismatch"): + Agent(client=client, middleware=[mismatched_middleware]) async def test_only_decorator_specified(self, chat_client_base: "MockBaseChatClient") -> None: """Only decorator specified - rely on decorator.""" @@ -1595,22 +1593,19 @@ async def no_info_middleware(context: Any, call_next: Any) -> None: # No decora # Should raise MiddlewareException with pytest.raises(MiddlewareException, match="Cannot determine middleware type"): - agent = Agent(client=client, middleware=[no_info_middleware]) - await agent.run([Message(role="user", contents=["test"])]) + Agent(client=client, middleware=[no_info_middleware]) async def test_insufficient_parameters_error(self, client: Any) -> None: """Test that middleware with insufficient parameters raises an error.""" from agent_framework import Agent, agent_middleware # Should raise MiddlewareException about insufficient parameters - with pytest.raises(MiddlewareException, match="must have at least 2 parameters"): - - @agent_middleware # type: ignore[arg-type] - async def insufficient_params_middleware(context: Any) -> None: # Missing 'next' parameter - pass + @agent_middleware # type: ignore[arg-type] + async def insufficient_params_middleware(context: Any) -> None: # Missing 'next' parameter + pass - agent = Agent(client=client, middleware=[insufficient_params_middleware]) - await agent.run([Message(role="user", contents=["test"])]) + with pytest.raises(MiddlewareException, match="must have at least 2 parameters"): + Agent(client=client, middleware=[insufficient_params_middleware]) async def test_decorator_markers_preserved(self) -> None: """Test that decorator markers are properly set on functions."""