Skip to content

Commit 7400a97

Browse files
authored
Check the python format in the GitHub action (google#538)
1 parent 80358e4 commit 7400a97

File tree

5 files changed

+157
-47
lines changed

5 files changed

+157
-47
lines changed

.github/workflows/python_a2ui_agent_build_and_test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
python -m pip install --upgrade pip
4343
pip install uv
4444
45+
- name: Check Formatting
46+
working-directory: a2a_agents/python/a2ui_agent
47+
run: uv run pyink --check .
48+
4549
- name: Build the python SDK
4650
working-directory: a2a_agents/python/a2ui_agent
4751
run: uv build .

a2a_agents/python/a2ui_agent/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ pyink-annotation-pragmas = [
4141
dev = [
4242
"pytest>=9.0.2",
4343
"pytest-asyncio>=1.3.0",
44+
"pyink>=24.10.0",
4445
]

a2a_agents/python/a2ui_agent/tests/extension/test_a2ui_extension.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222

2323
def test_a2ui_part_serialization():
24-
a2ui_data = {
25-
"beginRendering": {"surfaceId": "test-surface", "root": "root-column"}
26-
}
24+
a2ui_data = {"beginRendering": {"surfaceId": "test-surface", "root": "root-column"}}
2725

2826
part = a2ui_extension.create_a2ui_part(a2ui_data)
2927

@@ -41,9 +39,7 @@ def test_non_a2ui_data_part():
4139
metadata={"mimeType": "application/json"}, # Not A2UI
4240
)
4341
)
44-
assert not a2ui_extension.is_a2ui_part(
45-
part
46-
), "Should not be identified as A2UI part"
42+
assert not a2ui_extension.is_a2ui_part(part), "Should not be identified as A2UI part"
4743
assert (
4844
a2ui_extension.get_a2ui_datapart(part) is None
4945
), "Should not return A2UI DataPart"
@@ -53,9 +49,7 @@ def test_non_a2ui_part():
5349
text_part = TextPart(text="this is some text")
5450
part = Part(root=text_part)
5551

56-
assert not a2ui_extension.is_a2ui_part(
57-
part
58-
), "Should not be identified as A2UI part"
52+
assert not a2ui_extension.is_a2ui_part(part), "Should not be identified as A2UI part"
5953
assert (
6054
a2ui_extension.get_a2ui_datapart(part) is None
6155
), "Should not return A2UI DataPart"

a2a_agents/python/a2ui_agent/tests/extension/test_send_a2ui_to_client_toolset.py

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939

4040
@pytest.mark.asyncio
4141
async def test_toolset_init_bool():
42-
toolset = SendA2uiToClientToolset(
43-
a2ui_enabled=True, a2ui_schema=TEST_A2UI_SCHEMA
44-
)
42+
toolset = SendA2uiToClientToolset(a2ui_enabled=True, a2ui_schema=TEST_A2UI_SCHEMA)
4543
ctx = MagicMock(spec=ReadonlyContext)
4644
assert await toolset._resolve_a2ui_enabled(ctx) == True
4745

@@ -54,9 +52,7 @@ async def test_toolset_init_bool():
5452
async def test_toolset_init_callable():
5553
enabled_mock = MagicMock(return_value=True)
5654
schema_mock = MagicMock(return_value=TEST_A2UI_SCHEMA)
57-
toolset = SendA2uiToClientToolset(
58-
a2ui_enabled=enabled_mock, a2ui_schema=schema_mock
59-
)
55+
toolset = SendA2uiToClientToolset(a2ui_enabled=enabled_mock, a2ui_schema=schema_mock)
6056
ctx = MagicMock(spec=ReadonlyContext)
6157
assert await toolset._resolve_a2ui_enabled(ctx) == True
6258

@@ -88,19 +84,15 @@ async def async_schema(_ctx):
8884

8985
@pytest.mark.asyncio
9086
async def test_toolset_get_tools_enabled():
91-
toolset = SendA2uiToClientToolset(
92-
a2ui_enabled=True, a2ui_schema=TEST_A2UI_SCHEMA
93-
)
87+
toolset = SendA2uiToClientToolset(a2ui_enabled=True, a2ui_schema=TEST_A2UI_SCHEMA)
9488
tools = await toolset.get_tools(MagicMock(spec=ReadonlyContext))
9589
assert len(tools) == 1
9690
assert isinstance(tools[0], SendA2uiToClientToolset._SendA2uiJsonToClientTool)
9791

9892

9993
@pytest.mark.asyncio
10094
async def test_toolset_get_tools_disabled():
101-
toolset = SendA2uiToClientToolset(
102-
a2ui_enabled=False, a2ui_schema=TEST_A2UI_SCHEMA
103-
)
95+
toolset = SendA2uiToClientToolset(a2ui_enabled=False, a2ui_schema=TEST_A2UI_SCHEMA)
10496
tools = await toolset.get_tools(MagicMock(spec=ReadonlyContext))
10597
assert len(tools) == 0
10698

@@ -113,20 +105,15 @@ async def test_toolset_get_tools_disabled():
113105

114106
def test_send_tool_init():
115107
tool = SendA2uiToClientToolset._SendA2uiJsonToClientTool(TEST_A2UI_SCHEMA)
116-
assert (
117-
tool.name == SendA2uiToClientToolset._SendA2uiJsonToClientTool.TOOL_NAME
118-
)
108+
assert tool.name == SendA2uiToClientToolset._SendA2uiJsonToClientTool.TOOL_NAME
119109
assert tool._a2ui_schema == TEST_A2UI_SCHEMA
120110

121111

122112
def test_send_tool_get_declaration():
123113
tool = SendA2uiToClientToolset._SendA2uiJsonToClientTool(TEST_A2UI_SCHEMA)
124114
declaration = tool._get_declaration()
125115
assert declaration is not None
126-
assert (
127-
declaration.name
128-
== SendA2uiToClientToolset._SendA2uiJsonToClientTool.TOOL_NAME
129-
)
116+
assert declaration.name == SendA2uiToClientToolset._SendA2uiJsonToClientTool.TOOL_NAME
130117
assert (
131118
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME
132119
in declaration.parameters.properties
@@ -182,8 +169,8 @@ async def test_send_tool_run_async_valid():
182169

183170
valid_a2ui = [{"type": "Text", "text": "Hello"}]
184171
args = {
185-
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: (
186-
json.dumps(valid_a2ui)
172+
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: json.dumps(
173+
valid_a2ui
187174
)
188175
}
189176

@@ -205,8 +192,8 @@ async def test_send_tool_run_async_valid_list():
205192

206193
valid_a2ui = [{"type": "Text", "text": "Hello"}]
207194
args = {
208-
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: (
209-
json.dumps(valid_a2ui)
195+
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: json.dumps(
196+
valid_a2ui
210197
)
211198
}
212199

@@ -234,9 +221,7 @@ async def test_send_tool_run_async_missing_arg():
234221
async def test_send_tool_run_async_invalid_json():
235222
tool = SendA2uiToClientToolset._SendA2uiJsonToClientTool(TEST_A2UI_SCHEMA)
236223
args = {
237-
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: (
238-
"{invalid"
239-
)
224+
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: "{invalid"
240225
}
241226
result = await tool.run_async(args=args, tool_context=MagicMock())
242227
assert "error" in result
@@ -248,8 +233,8 @@ async def test_send_tool_run_async_schema_validation_fail():
248233
tool = SendA2uiToClientToolset._SendA2uiJsonToClientTool(TEST_A2UI_SCHEMA)
249234
invalid_a2ui = [{"type": "Text"}] # Missing 'text'
250235
args = {
251-
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: (
252-
json.dumps(invalid_a2ui)
236+
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: json.dumps(
237+
invalid_a2ui
253238
)
254239
}
255240
result = await tool.run_async(args=args, tool_context=MagicMock())
@@ -307,9 +292,7 @@ def test_converter_convert_function_call_returns_empty():
307292
function_call = genai_types.FunctionCall(
308293
name=SendA2uiToClientToolset._SendA2uiJsonToClientTool.TOOL_NAME,
309294
args={
310-
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: (
311-
"..."
312-
)
295+
SendA2uiToClientToolset._SendA2uiJsonToClientTool.A2UI_JSON_ARG_NAME: "..."
313296
},
314297
)
315298
part = genai_types.Part(function_call=function_call)
@@ -337,9 +320,7 @@ def test_converter_convert_empty_result_response():
337320
assert len(a2a_parts) == 0
338321

339322

340-
@patch(
341-
"google.adk.a2a.converters.part_converter.convert_genai_part_to_a2a_part"
342-
)
323+
@patch("google.adk.a2a.converters.part_converter.convert_genai_part_to_a2a_part")
343324
def test_converter_convert_non_a2ui_function_call(mock_convert):
344325
function_call = genai_types.FunctionCall(name="other_tool", args={})
345326
part = genai_types.Part(function_call=function_call)
@@ -352,9 +333,7 @@ def test_converter_convert_non_a2ui_function_call(mock_convert):
352333
mock_convert.assert_called_once_with(part)
353334

354335

355-
@patch(
356-
"google.adk.a2a.converters.part_converter.convert_genai_part_to_a2a_part"
357-
)
336+
@patch("google.adk.a2a.converters.part_converter.convert_genai_part_to_a2a_part")
358337
def test_converter_convert_other_part(mock_convert):
359338
part = genai_types.Part(text="Hello")
360339
mock_a2a_part = a2a_types.Part(root=a2a_types.TextPart(text="Hello"))

0 commit comments

Comments
 (0)