Skip to content

Commit 5f258f7

Browse files
committed
Formatting/fixes
1 parent fbe7310 commit 5f258f7

16 files changed

+209
-202
lines changed

tests/client/test_auth_middleware.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,8 @@ def store():
108108
@pytest.mark.asyncio
109109
async def test_auth_interceptor_skips_when_no_agent_card(
110110
store: InMemoryContextCredentialStore,
111-
):
112-
"""
113-
Tests that the AuthInterceptor does not modify the request when no AgentCard is provided.
114-
"""
111+
) -> None:
112+
"""Tests that the AuthInterceptor does not modify the request when no AgentCard is provided."""
115113
request_payload = {'foo': 'bar'}
116114
http_kwargs = {'fizz': 'buzz'}
117115
auth_interceptor = AuthInterceptor(credential_service=store)
@@ -130,9 +128,8 @@ async def test_auth_interceptor_skips_when_no_agent_card(
130128
@pytest.mark.asyncio
131129
async def test_in_memory_context_credential_store(
132130
store: InMemoryContextCredentialStore,
133-
):
134-
"""
135-
Verifies that InMemoryContextCredentialStore correctly stores and retrieves
131+
) -> None:
132+
"""Verifies that InMemoryContextCredentialStore correctly stores and retrieves
136133
credentials based on the session ID in the client context.
137134
"""
138135
session_id = 'session-id'
@@ -167,11 +164,8 @@ async def test_in_memory_context_credential_store(
167164

168165
@pytest.mark.asyncio
169166
@respx.mock
170-
async def test_client_with_simple_interceptor():
171-
"""
172-
Ensures that a custom HeaderInterceptor correctly injects a static header
173-
into outbound HTTP requests from the A2AClient.
174-
"""
167+
async def test_client_with_simple_interceptor() -> None:
168+
"""Ensures that a custom HeaderInterceptor correctly injects a static header into outbound HTTP requests from the A2AClient."""
175169
url = 'http://agent.com/rpc'
176170
interceptor = HeaderInterceptor('X-Test-Header', 'Test-Value-123')
177171
card = AgentCard(
@@ -200,9 +194,7 @@ async def test_client_with_simple_interceptor():
200194

201195
@dataclass
202196
class AuthTestCase:
203-
"""
204-
Represents a test scenario for verifying authentication behavior in AuthInterceptor.
205-
"""
197+
"""Represents a test scenario for verifying authentication behavior in AuthInterceptor."""
206198

207199
url: str
208200
"""The endpoint URL of the agent to which the request is sent."""
@@ -290,11 +282,8 @@ class AuthTestCase:
290282
@respx.mock
291283
async def test_auth_interceptor_variants(
292284
test_case: AuthTestCase, store: InMemoryContextCredentialStore
293-
):
294-
"""
295-
Parametrized test verifying that AuthInterceptor correctly attaches credentials
296-
based on the defined security scheme in the AgentCard.
297-
"""
285+
) -> None:
286+
"""Parametrized test verifying that AuthInterceptor correctly attaches credentials based on the defined security scheme in the AgentCard."""
298287
await store.set_credentials(
299288
test_case.session_id, test_case.scheme_name, test_case.credential
300289
)
@@ -336,11 +325,8 @@ async def test_auth_interceptor_variants(
336325
@pytest.mark.asyncio
337326
async def test_auth_interceptor_skips_when_scheme_not_in_security_schemes(
338327
store: InMemoryContextCredentialStore,
339-
):
340-
"""
341-
Tests that AuthInterceptor skips a scheme if it's listed in security requirements
342-
but not defined in security_schemes.
343-
"""
328+
) -> None:
329+
"""Tests that AuthInterceptor skips a scheme if it's listed in security requirements but not defined in security_schemes."""
344330
scheme_name = 'missing'
345331
session_id = 'session-id'
346332
credential = 'dummy-token'

tests/client/test_base_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def base_client(
6363
@pytest.mark.asyncio
6464
async def test_send_message_streaming(
6565
base_client: BaseClient, mock_transport: MagicMock, sample_message: Message
66-
):
66+
) -> None:
6767
async def create_stream(*args, **kwargs):
6868
yield Task(
6969
id='task-123',
@@ -84,7 +84,7 @@ async def create_stream(*args, **kwargs):
8484
@pytest.mark.asyncio
8585
async def test_send_message_non_streaming(
8686
base_client: BaseClient, mock_transport: MagicMock, sample_message: Message
87-
):
87+
) -> None:
8888
base_client._config.streaming = False
8989
mock_transport.send_message.return_value = Task(
9090
id='task-456',
@@ -103,7 +103,7 @@ async def test_send_message_non_streaming(
103103
@pytest.mark.asyncio
104104
async def test_send_message_non_streaming_agent_capability_false(
105105
base_client: BaseClient, mock_transport: MagicMock, sample_message: Message
106-
):
106+
) -> None:
107107
base_client._card.capabilities.streaming = False
108108
mock_transport.send_message.return_value = Task(
109109
id='task-789',

tests/client/test_client_task_manager.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,23 @@ def sample_message() -> Message:
4646
)
4747

4848

49-
def test_get_task_no_task_id_returns_none(task_manager: ClientTaskManager):
49+
def test_get_task_no_task_id_returns_none(
50+
task_manager: ClientTaskManager,
51+
) -> None:
5052
assert task_manager.get_task() is None
5153

5254

5355
def test_get_task_or_raise_no_task_raises_error(
5456
task_manager: ClientTaskManager,
55-
):
57+
) -> None:
5658
with pytest.raises(A2AClientInvalidStateError, match='no current Task'):
5759
task_manager.get_task_or_raise()
5860

5961

6062
@pytest.mark.asyncio
6163
async def test_save_task_event_with_task(
6264
task_manager: ClientTaskManager, sample_task: Task
63-
):
65+
) -> None:
6466
await task_manager.save_task_event(sample_task)
6567
assert task_manager.get_task() == sample_task
6668
assert task_manager._task_id == sample_task.id
@@ -70,7 +72,7 @@ async def test_save_task_event_with_task(
7072
@pytest.mark.asyncio
7173
async def test_save_task_event_with_task_already_set_raises_error(
7274
task_manager: ClientTaskManager, sample_task: Task
73-
):
75+
) -> None:
7476
await task_manager.save_task_event(sample_task)
7577
with pytest.raises(
7678
A2AClientInvalidArgsError,
@@ -82,7 +84,7 @@ async def test_save_task_event_with_task_already_set_raises_error(
8284
@pytest.mark.asyncio
8385
async def test_save_task_event_with_status_update(
8486
task_manager: ClientTaskManager, sample_task: Task, sample_message: Message
85-
):
87+
) -> None:
8688
await task_manager.save_task_event(sample_task)
8789
status_update = TaskStatusUpdateEvent(
8890
task_id=sample_task.id,
@@ -98,7 +100,7 @@ async def test_save_task_event_with_status_update(
98100
@pytest.mark.asyncio
99101
async def test_save_task_event_with_artifact_update(
100102
task_manager: ClientTaskManager, sample_task: Task
101-
):
103+
) -> None:
102104
await task_manager.save_task_event(sample_task)
103105
artifact = Artifact(
104106
artifact_id='art1', parts=[Part(root=TextPart(text='artifact content'))]
@@ -119,7 +121,7 @@ async def test_save_task_event_with_artifact_update(
119121
@pytest.mark.asyncio
120122
async def test_save_task_event_creates_task_if_not_exists(
121123
task_manager: ClientTaskManager,
122-
):
124+
) -> None:
123125
status_update = TaskStatusUpdateEvent(
124126
task_id='new_task',
125127
context_id='new_context',
@@ -135,7 +137,7 @@ async def test_save_task_event_creates_task_if_not_exists(
135137
@pytest.mark.asyncio
136138
async def test_process_with_task_event(
137139
task_manager: ClientTaskManager, sample_task: Task
138-
):
140+
) -> None:
139141
with patch.object(
140142
task_manager, 'save_task_event', new_callable=AsyncMock
141143
) as mock_save:
@@ -144,7 +146,9 @@ async def test_process_with_task_event(
144146

145147

146148
@pytest.mark.asyncio
147-
async def test_process_with_non_task_event(task_manager: ClientTaskManager):
149+
async def test_process_with_non_task_event(
150+
task_manager: ClientTaskManager,
151+
) -> None:
148152
with patch.object(
149153
task_manager, 'save_task_event', new_callable=Mock
150154
) as mock_save:
@@ -155,14 +159,14 @@ async def test_process_with_non_task_event(task_manager: ClientTaskManager):
155159

156160
def test_update_with_message(
157161
task_manager: ClientTaskManager, sample_task: Task, sample_message: Message
158-
):
162+
) -> None:
159163
updated_task = task_manager.update_with_message(sample_message, sample_task)
160164
assert updated_task.history == [sample_message]
161165

162166

163167
def test_update_with_message_moves_status_message(
164168
task_manager: ClientTaskManager, sample_task: Task, sample_message: Message
165-
):
169+
) -> None:
166170
status_message = Message(
167171
message_id='status_msg',
168172
role=Role.agent,

tests/client/test_errors.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import NoReturn
2+
13
import pytest
24

35
from a2a.client import A2AClientError, A2AClientHTTPError, A2AClientJSONError
@@ -6,13 +8,13 @@
68
class TestA2AClientError:
79
"""Test cases for the base A2AClientError class."""
810

9-
def test_instantiation(self):
11+
def test_instantiation(self) -> None:
1012
"""Test that A2AClientError can be instantiated."""
1113
error = A2AClientError('Test error message')
1214
assert isinstance(error, Exception)
1315
assert str(error) == 'Test error message'
1416

15-
def test_inheritance(self):
17+
def test_inheritance(self) -> None:
1618
"""Test that A2AClientError inherits from Exception."""
1719
error = A2AClientError()
1820
assert isinstance(error, Exception)
@@ -21,31 +23,31 @@ def test_inheritance(self):
2123
class TestA2AClientHTTPError:
2224
"""Test cases for A2AClientHTTPError class."""
2325

24-
def test_instantiation(self):
26+
def test_instantiation(self) -> None:
2527
"""Test that A2AClientHTTPError can be instantiated with status_code and message."""
2628
error = A2AClientHTTPError(404, 'Not Found')
2729
assert isinstance(error, A2AClientError)
2830
assert error.status_code == 404
2931
assert error.message == 'Not Found'
3032

31-
def test_message_formatting(self):
33+
def test_message_formatting(self) -> None:
3234
"""Test that the error message is formatted correctly."""
3335
error = A2AClientHTTPError(500, 'Internal Server Error')
3436
assert str(error) == 'HTTP Error 500: Internal Server Error'
3537

36-
def test_inheritance(self):
38+
def test_inheritance(self) -> None:
3739
"""Test that A2AClientHTTPError inherits from A2AClientError."""
3840
error = A2AClientHTTPError(400, 'Bad Request')
3941
assert isinstance(error, A2AClientError)
4042

41-
def test_with_empty_message(self):
43+
def test_with_empty_message(self) -> None:
4244
"""Test behavior with an empty message."""
4345
error = A2AClientHTTPError(403, '')
4446
assert error.status_code == 403
4547
assert error.message == ''
4648
assert str(error) == 'HTTP Error 403: '
4749

48-
def test_with_various_status_codes(self):
50+
def test_with_various_status_codes(self) -> None:
4951
"""Test with different HTTP status codes."""
5052
test_cases = [
5153
(200, 'OK'),
@@ -68,29 +70,29 @@ def test_with_various_status_codes(self):
6870
class TestA2AClientJSONError:
6971
"""Test cases for A2AClientJSONError class."""
7072

71-
def test_instantiation(self):
73+
def test_instantiation(self) -> None:
7274
"""Test that A2AClientJSONError can be instantiated with a message."""
7375
error = A2AClientJSONError('Invalid JSON format')
7476
assert isinstance(error, A2AClientError)
7577
assert error.message == 'Invalid JSON format'
7678

77-
def test_message_formatting(self):
79+
def test_message_formatting(self) -> None:
7880
"""Test that the error message is formatted correctly."""
7981
error = A2AClientJSONError('Missing required field')
8082
assert str(error) == 'JSON Error: Missing required field'
8183

82-
def test_inheritance(self):
84+
def test_inheritance(self) -> None:
8385
"""Test that A2AClientJSONError inherits from A2AClientError."""
8486
error = A2AClientJSONError('Parsing error')
8587
assert isinstance(error, A2AClientError)
8688

87-
def test_with_empty_message(self):
89+
def test_with_empty_message(self) -> None:
8890
"""Test behavior with an empty message."""
8991
error = A2AClientJSONError('')
9092
assert error.message == ''
9193
assert str(error) == 'JSON Error: '
9294

93-
def test_with_various_messages(self):
95+
def test_with_various_messages(self) -> None:
9496
"""Test with different error messages."""
9597
test_messages = [
9698
'Malformed JSON',
@@ -109,21 +111,21 @@ def test_with_various_messages(self):
109111
class TestExceptionHierarchy:
110112
"""Test the exception hierarchy and relationships."""
111113

112-
def test_exception_hierarchy(self):
114+
def test_exception_hierarchy(self) -> None:
113115
"""Test that the exception hierarchy is correct."""
114116
assert issubclass(A2AClientError, Exception)
115117
assert issubclass(A2AClientHTTPError, A2AClientError)
116118
assert issubclass(A2AClientJSONError, A2AClientError)
117119

118-
def test_catch_specific_exception(self):
120+
def test_catch_specific_exception(self) -> None:
119121
"""Test that specific exceptions can be caught."""
120122
try:
121123
raise A2AClientHTTPError(404, 'Not Found')
122124
except A2AClientHTTPError as e:
123125
assert e.status_code == 404
124126
assert e.message == 'Not Found'
125127

126-
def test_catch_base_exception(self):
128+
def test_catch_base_exception(self) -> None:
127129
"""Test that derived exceptions can be caught as base exception."""
128130
exceptions = [
129131
A2AClientHTTPError(404, 'Not Found'),
@@ -140,7 +142,7 @@ def test_catch_base_exception(self):
140142
class TestExceptionRaising:
141143
"""Test cases for raising and handling the exceptions."""
142144

143-
def test_raising_http_error(self):
145+
def test_raising_http_error(self) -> NoReturn:
144146
"""Test raising an HTTP error and checking its properties."""
145147
with pytest.raises(A2AClientHTTPError) as excinfo:
146148
raise A2AClientHTTPError(429, 'Too Many Requests')
@@ -150,7 +152,7 @@ def test_raising_http_error(self):
150152
assert error.message == 'Too Many Requests'
151153
assert str(error) == 'HTTP Error 429: Too Many Requests'
152154

153-
def test_raising_json_error(self):
155+
def test_raising_json_error(self) -> NoReturn:
154156
"""Test raising a JSON error and checking its properties."""
155157
with pytest.raises(A2AClientJSONError) as excinfo:
156158
raise A2AClientJSONError('Invalid format')
@@ -159,7 +161,7 @@ def test_raising_json_error(self):
159161
assert error.message == 'Invalid format'
160162
assert str(error) == 'JSON Error: Invalid format'
161163

162-
def test_raising_base_error(self):
164+
def test_raising_base_error(self) -> NoReturn:
163165
"""Test raising the base error."""
164166
with pytest.raises(A2AClientError) as excinfo:
165167
raise A2AClientError('Generic client error')
@@ -178,7 +180,9 @@ def test_raising_base_error(self):
178180
(500, 'Server Error', 'HTTP Error 500: Server Error'),
179181
],
180182
)
181-
def test_http_error_parametrized(status_code: int, message: str, expected: str):
183+
def test_http_error_parametrized(
184+
status_code: int, message: str, expected: str
185+
) -> None:
182186
"""Parametrized test for HTTP errors with different status codes."""
183187
error = A2AClientHTTPError(status_code, message)
184188
assert error.status_code == status_code
@@ -194,7 +198,7 @@ def test_http_error_parametrized(status_code: int, message: str, expected: str):
194198
('Parsing failed', 'JSON Error: Parsing failed'),
195199
],
196200
)
197-
def test_json_error_parametrized(message: str, expected: str):
201+
def test_json_error_parametrized(message: str, expected: str) -> None:
198202
"""Parametrized test for JSON errors with different messages."""
199203
error = A2AClientJSONError(message)
200204
assert error.message == message

0 commit comments

Comments
 (0)