Skip to content

Commit 9182fdb

Browse files
committed
formatting
1 parent e57c8f7 commit 9182fdb

10 files changed

Lines changed: 136 additions & 107 deletions

File tree

src/a2a/client/__init__.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
except ImportError as e:
3232
_original_error = e
3333
logger.debug(
34-
"A2AGrpcClient not loaded. This is expected if gRPC dependencies are not installed. Error: %s",
34+
'A2AGrpcClient not loaded. This is expected if gRPC dependencies are not installed. Error: %s',
3535
_original_error,
3636
)
3737

@@ -40,29 +40,29 @@ class A2AGrpcClient: # type: ignore
4040

4141
def __init__(self, *args, **kwargs):
4242
raise ImportError(
43-
"To use A2AGrpcClient, its dependencies must be installed. "
43+
'To use A2AGrpcClient, its dependencies must be installed. '
4444
'You can install them with \'pip install "a2a-sdk[grpc]"\''
4545
) from _original_error
4646

4747

4848
__all__ = [
49-
"A2ACardResolver",
50-
"A2AClient",
51-
"A2AClientError",
52-
"A2AClientHTTPError",
53-
"A2AClientJSONError",
54-
"A2AClientTimeoutError",
55-
"A2AGrpcClient",
56-
"AuthInterceptor",
57-
"Client",
58-
"ClientCallContext",
59-
"ClientCallInterceptor",
60-
"ClientConfig",
61-
"ClientEvent",
62-
"ClientFactory",
63-
"Consumer",
64-
"CredentialService",
65-
"InMemoryContextCredentialStore",
66-
"create_text_message_object",
67-
"minimal_agent_card",
49+
'A2ACardResolver',
50+
'A2AClient',
51+
'A2AClientError',
52+
'A2AClientHTTPError',
53+
'A2AClientJSONError',
54+
'A2AClientTimeoutError',
55+
'A2AGrpcClient',
56+
'AuthInterceptor',
57+
'Client',
58+
'ClientCallContext',
59+
'ClientCallInterceptor',
60+
'ClientConfig',
61+
'ClientEvent',
62+
'ClientFactory',
63+
'Consumer',
64+
'CredentialService',
65+
'InMemoryContextCredentialStore',
66+
'create_text_message_object',
67+
'minimal_agent_card',
6868
]

src/a2a/client/legacy_grpc.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@
88

99

1010
class A2AGrpcClient(GrpcTransport):
11-
"""
12-
[DEPRECATED] Backwards compatibility wrapper for the gRPC client.
13-
"""
11+
"""[DEPRECATED] Backwards compatibility wrapper for the gRPC client."""
1412

1513
def __init__(
1614
self,
17-
grpc_stub: "a2a_pb2_grpc.A2AServiceStub",
15+
grpc_stub: 'a2a_pb2_grpc.A2AServiceStub',
1816
agent_card: AgentCard,
1917
):
2018
warnings.warn(
21-
"A2AGrpcClient is deprecated and will be removed in a future version. "
22-
"Use ClientFactory to create a client with a gRPC transport.",
19+
'A2AGrpcClient is deprecated and will be removed in a future version. '
20+
'Use ClientFactory to create a client with a gRPC transport.',
2321
DeprecationWarning,
2422
stacklevel=2,
2523
)
26-
super().__init__(grpc_stub, agent_card)
24+
super().__init__(grpc_stub, agent_card)

src/a2a/client/transports/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313

1414
__all__ = [
15-
"ClientTransport",
16-
"GrpcTransport",
17-
"JsonRpcTransport",
18-
"RestTransport",
15+
'ClientTransport',
16+
'GrpcTransport',
17+
'JsonRpcTransport',
18+
'RestTransport',
1919
]

src/a2a/utils/proto_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
# Regexp patterns for matching
2121
_TASK_NAME_MATCH = r'tasks/([\w-]+)'
22-
_TASK_PUSH_CONFIG_NAME_MATCH = r'tasks/([\w-]+)/pushNotificationConfigs/([\w-]+)'
22+
_TASK_PUSH_CONFIG_NAME_MATCH = (
23+
r'tasks/([\w-]+)/pushNotificationConfigs/([\w-]+)'
24+
)
2325

2426

2527
class ToProto:

tests/client/test_auth_middleware.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
23
from collections.abc import Callable
34
from dataclasses import dataclass
45
from typing import Any
@@ -17,9 +18,9 @@
1718
InMemoryContextCredentialStore,
1819
)
1920
from a2a.types import (
21+
APIKeySecurityScheme,
2022
AgentCapabilities,
2123
AgentCard,
22-
APIKeySecurityScheme,
2324
AuthorizationCodeOAuthFlow,
2425
HTTPAuthSecurityScheme,
2526
In,

tests/client/test_client_factory.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from a2a.client import ClientConfig, ClientFactory
77
from a2a.client.transports import JsonRpcTransport, RestTransport
88
from a2a.types import (
9-
AgentCard,
109
AgentCapabilities,
10+
AgentCard,
1111
AgentInterface,
1212
TransportProtocol,
1313
)
@@ -17,10 +17,10 @@
1717
def base_agent_card() -> AgentCard:
1818
"""Provides a base AgentCard for tests."""
1919
return AgentCard(
20-
name="Test Agent",
21-
description="An agent for testing.",
22-
url="http://primary-url.com",
23-
version="1.0.0",
20+
name='Test Agent',
21+
description='An agent for testing.',
22+
url='http://primary-url.com',
23+
version='1.0.0',
2424
capabilities=AgentCapabilities(),
2525
skills=[],
2626
default_input_modes=[],
@@ -33,53 +33,65 @@ def test_client_factory_selects_preferred_transport(base_agent_card: AgentCard):
3333
"""Verify that the factory selects the preferred transport by default."""
3434
config = ClientConfig(
3535
httpx_client=httpx.AsyncClient(),
36-
supported_transports=[TransportProtocol.jsonrpc, TransportProtocol.http_json],
36+
supported_transports=[
37+
TransportProtocol.jsonrpc,
38+
TransportProtocol.http_json,
39+
],
3740
)
3841
factory = ClientFactory(config)
3942
client = factory.create(base_agent_card)
4043

4144
assert isinstance(client._transport, JsonRpcTransport)
42-
assert client._transport.url == "http://primary-url.com"
45+
assert client._transport.url == 'http://primary-url.com'
4346

4447

45-
def test_client_factory_selects_secondary_transport_url(base_agent_card: AgentCard):
48+
def test_client_factory_selects_secondary_transport_url(
49+
base_agent_card: AgentCard,
50+
):
4651
"""Verify that the factory selects the correct URL for a secondary transport."""
4752
base_agent_card.additional_interfaces = [
4853
AgentInterface(
49-
transport=TransportProtocol.http_json, url="http://secondary-url.com"
54+
transport=TransportProtocol.http_json,
55+
url='http://secondary-url.com',
5056
)
5157
]
5258
# Client prefers REST, which is available as a secondary transport
5359
config = ClientConfig(
5460
httpx_client=httpx.AsyncClient(),
55-
supported_transports=[TransportProtocol.http_json, TransportProtocol.jsonrpc],
61+
supported_transports=[
62+
TransportProtocol.http_json,
63+
TransportProtocol.jsonrpc,
64+
],
5665
use_client_preference=True,
5766
)
5867
factory = ClientFactory(config)
5968
client = factory.create(base_agent_card)
6069

6170
assert isinstance(client._transport, RestTransport)
62-
assert client._transport.url == "http://secondary-url.com"
71+
assert client._transport.url == 'http://secondary-url.com'
6372

6473

6574
def test_client_factory_server_preference(base_agent_card: AgentCard):
6675
"""Verify that the factory respects server transport preference."""
6776
base_agent_card.preferred_transport = TransportProtocol.http_json
6877
base_agent_card.additional_interfaces = [
6978
AgentInterface(
70-
transport=TransportProtocol.jsonrpc, url="http://secondary-url.com"
79+
transport=TransportProtocol.jsonrpc, url='http://secondary-url.com'
7180
)
7281
]
7382
# Client supports both, but server prefers REST
7483
config = ClientConfig(
7584
httpx_client=httpx.AsyncClient(),
76-
supported_transports=[TransportProtocol.jsonrpc, TransportProtocol.http_json],
85+
supported_transports=[
86+
TransportProtocol.jsonrpc,
87+
TransportProtocol.http_json,
88+
],
7789
)
7890
factory = ClientFactory(config)
7991
client = factory.create(base_agent_card)
8092

8193
assert isinstance(client._transport, RestTransport)
82-
assert client._transport.url == "http://primary-url.com"
94+
assert client._transport.url == 'http://primary-url.com'
8395

8496

8597
def test_client_factory_no_compatible_transport(base_agent_card: AgentCard):
@@ -89,5 +101,5 @@ def test_client_factory_no_compatible_transport(base_agent_card: AgentCard):
89101
supported_transports=[TransportProtocol.grpc],
90102
)
91103
factory = ClientFactory(config)
92-
with pytest.raises(ValueError, match="no compatible transports found"):
104+
with pytest.raises(ValueError, match='no compatible transports found'):
93105
factory.create(base_agent_card)

tests/client/test_jsonrpc_client.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import json
2+
23
from collections.abc import AsyncGenerator
34
from typing import Any
4-
from unittest.mock import ANY, AsyncMock, MagicMock, patch
5+
from unittest.mock import AsyncMock, MagicMock, patch
56

67
import httpx
78
import pytest
8-
from httpx_sse import EventSource, ServerSentEvent, SSEError
9+
10+
from httpx_sse import EventSource, SSEError, ServerSentEvent
911

1012
from a2a.client import (
1113
A2ACardResolver,
@@ -27,12 +29,12 @@
2729
SendMessageSuccessResponse,
2830
Task,
2931
TaskIdParams,
30-
TaskNotCancelableError,
3132
TaskPushNotificationConfig,
3233
TaskQueryParams,
3334
)
3435
from a2a.utils import AGENT_CARD_WELL_KNOWN_PATH
3536

37+
3638
AGENT_CARD = AgentCard(
3739
name='Hello World Agent',
3840
description='Just a hello world agent',
@@ -550,9 +552,10 @@ async def test_get_task_success(
550552
response = await client.get_task(request=params)
551553

552554
assert isinstance(response, Task)
553-
assert response.model_dump() == Task.model_validate(
554-
MINIMAL_TASK
555-
).model_dump()
555+
assert (
556+
response.model_dump()
557+
== Task.model_validate(MINIMAL_TASK).model_dump()
558+
)
556559
mock_send_request.assert_called_once()
557560
sent_payload = mock_send_request.call_args.args[0]
558561
assert sent_payload['method'] == 'tasks/get'
@@ -577,9 +580,10 @@ async def test_cancel_task_success(
577580
response = await client.cancel_task(request=params)
578581

579582
assert isinstance(response, Task)
580-
assert response.model_dump() == Task.model_validate(
581-
MINIMAL_CANCELLED_TASK
582-
).model_dump()
583+
assert (
584+
response.model_dump()
585+
== Task.model_validate(MINIMAL_CANCELLED_TASK).model_dump()
586+
)
583587
mock_send_request.assert_called_once()
584588
sent_payload = mock_send_request.call_args.args[0]
585589
assert sent_payload['method'] == 'tasks/cancel'
@@ -731,7 +735,9 @@ async def test_send_message_streaming_request_error(
731735
]
732736

733737
@pytest.mark.asyncio
734-
async def test_get_card_no_card_provided(self, mock_httpx_client: AsyncMock):
738+
async def test_get_card_no_card_provided(
739+
self, mock_httpx_client: AsyncMock
740+
):
735741
client = JsonRpcTransport(
736742
httpx_client=mock_httpx_client, url=self.AGENT_URL
737743
)

tests/client/test_legacy_client.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from a2a.types import (
1010
AgentCapabilities,
1111
AgentCard,
12-
GetTaskRequest,
1312
Message,
1413
MessageSendParams,
1514
Part,
@@ -72,26 +71,12 @@ async def test_a2a_client_send_message(
7271
"""Tests for the legacy client compatibility layer."""
7372

7473

75-
from unittest.mock import AsyncMock, MagicMock
74+
from unittest.mock import AsyncMock
7675

77-
import httpx
7876
import pytest
7977

80-
from a2a.client import A2AClient, A2AGrpcClient
8178
from a2a.types import (
82-
AgentCapabilities,
8379
AgentCard,
84-
GetTaskRequest,
85-
Message,
86-
MessageSendParams,
87-
Part,
88-
Role,
89-
SendMessageRequest,
90-
Task,
91-
TaskQueryParams,
92-
TaskState,
93-
TaskStatus,
94-
TextPart,
9580
)
9681

9782

0 commit comments

Comments
 (0)