8000 chore: auto-format files. · miketako3/adk-python@4214c7e · GitHub
[go: up one dir, main page]

Skip to content

Commit 4214c7e

Browse files
Jacksunweicopybara-github
authored andcommitted
chore: auto-format files.
PiperOrigin-RevId: 764980009
1 parent face2e8 commit 4214c7e

File tree

4 files changed

+93
-77
lines changed

4 files changed

+93
-77
lines changed

src/google/adk/cli/cli_tools_click.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ class HelpfulCommand(click.Command):
5959

6060
def __init__(self, *args, **kwargs):
6161
super().__init__(*args, **kwargs)
62-
62+
6363
@staticmethod
6464
def _format_missing_arg_error(click_exception):
6565
"""Format the missing argument error with uppercase parameter name.
66-
66+
6767
Args:
6868
click_exception: The MissingParameter exception from Click.
69-
69+
7070
Returns:
7171
str: Formatted error message with uppercase parameter name.
7272
"""

src/google/adk/tools/transfer_to_agent_tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
def transfer_to_agent(agent_name: str, tool_context: ToolContext):
1919
"""Transfer the question to another agent.
2020
21-
This tool hands off control to another agent when it's more suitable to
21+
This tool hands off control to another agent when it's more suitable to
2222
answer the user's question according to the agent's description.
23-
23+
2424
Args:
2525
agent_name: the agent name to transfer to.
2626
"""

tests/unittests/code_executors/test_built_in_code_executor.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import pytest
15-
from google.genai import types
1614

1715
from google.adk.code_executors.built_in_code_executor import BuiltInCodeExecutor
1816
from google.adk.models.llm_request import LlmRequest
17+
from google.genai import types
18+
import pytest
1919

2020

2121
@pytest.fixture
@@ -78,9 +78,10 @@ def test_process_llm_request_gemini_2_model_with_existing_tools(
7878
built_in_executor.process_llm_request(llm_request)
7979
assert len(llm_request.config.tools) == 2
8080
assert existing_tool in llm_request.config.tools
81-
assert types.Tool(
82-
code_execution=types.ToolCodeExecution()
83-
) in llm_request.config.tools
81+
assert (
82+
types.Tool(code_execution=types.ToolCodeExecution())
83+
in llm_request.config.tools
84+
)
8485

8586

8687
def test_process_llm_request_non_gemini_2_model(
@@ -100,10 +101,9 @@ def test_process_llm_request_no_model_name(
100101
built_in_executor: BuiltInCodeExecutor,
101102
):
102103
"""Tests that a ValueError is raised if model name is not set."""
103-
llm_request = LlmRequest() # Model name defaults to None
104+
llm_request = LlmRequest() # Model name defaults to None
104105
with pytest.raises(ValueError) as excinfo:
105106
built_in_executor.process_llm_request(llm_request)
106-
assert (
107-
"Gemini code execution tool is not supported for model None"
108-
in str(excinfo.value)
109-
)
107+
assert "Gemini code execution tool is not supported for model None" in str(
108+
excinfo.value
109+
)

tests/unittests/code_executors/test_unsafe_local_code_executor.py

Lines changed: 78 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,76 +12,92 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import pytest
1615
from unittest.mock import MagicMock
17-
from google.adk.code_executors.unsafe_local_code_executor import UnsafeLocalCodeExecutor
18-
from google.adk.code_executors.code_execution_utils import CodeExecutionInput, CodeExecutionResult
19-
from google.adk.agents.invocation_context import InvocationContext
16+
2017
from google.adk.agents.base_agent import BaseAgent
21-
from google.adk.sessions.session import Session
18+
from google.adk.agents.invocation_context import InvocationContext
19+
from google.adk.code_executors.code_execution_utils import CodeExecutionInput
20+
from google.adk.code_executors.code_execution_utils import CodeExecutionResult
21+
from google.adk.code_executors.unsafe_local_code_executor import UnsafeLocalCodeExecutor
2222
from google.adk.sessions.base_session_service import BaseSessionService
23+
from google.adk.sessions.session import Session
24+
import pytest
2325

2426

2527
@pytest.fixture
2628
def mock_invocation_context() -> InvocationContext:
27-
"""Provides a mock InvocationContext."""
28-
mock_agent = MagicMock(spec=BaseAgent)
29-
mock_session = MagicMock(spec=Session)
30-
mock_session_service = MagicMock(spec=BaseSessionService)
31-
return InvocationContext(
32-
invocation_id="test_invocation",
33-
agent=mock_agent,
34-
session=mock_session,
35-
session_service=mock_session_service
36-
)
29+
"""Provides a mock InvocationContext."""
30+
mock_agent = MagicMock(spec=BaseAgent)
31+
mock_session = MagicMock(spec=Session)
32+
mock_session_service = MagicMock(< F438 span class="pl-s1">spec=BaseSessionService)
33+
return InvocationContext(
34+
invocation_id="test_invocation",
35+
agent=mock_agent,
36+
session=mock_session,
37+
session_service=mock_session_service,
38+
)
3739

3840

3941
class TestUnsafeLocalCodeExecutor:
4042

41-
def test_init_default(self):
42-
executor = UnsafeLocalCodeExecutor()
43-
assert not executor.stateful
44-
assert not executor.optimize_data_file
45-
46-
def test_init_stateful_raises_error(self):
47-
with pytest.raises(ValueError, match="Cannot set `stateful=True` in UnsafeLocalCodeExecutor."):
48-
UnsafeLocalCodeExecutor(stateful=True)
49-
50-
def test_init_optimize_data_file_raises_error(self):
51-
with pytest.raises(ValueError, match="Cannot set `optimize_data_file=True` in UnsafeLocalCodeExecutor."):
52-
UnsafeLocalCodeExecutor(optimize_data_file=True)
53-
54-
def test_execute_code_simple_print(self, mock_invocation_context: InvocationContext):
55-
executor = UnsafeLocalCodeExecutor()
56-
code_input = CodeExecutionInput(code='print("hello world")')
57-
result = executor.execute_code(mock_invocation_context, code_input)
58-
59-
assert isinstance(result, CodeExecutionResult)
60-
assert result.stdout == "hello world\n"
61-
assert result.stderr == ""
62-
assert result.output_files == []
63-
64-
def test_execute_code_with_error(self, mock_invocation_context: InvocationContext):
65-
executor = UnsafeLocalCodeExecutor()
66-
code_input = CodeExecutionInput(code='raise ValueError("Test error")')
67-
result = executor.execute_code(mock_invocation_context, code_input)
68-
69-
assert isinstance(result, CodeExecutionResult)
70-
assert result.stdout == ""
71-
assert "Test error" in result.stderr
72-
assert result.output_files == []
73-
74-
def test_execute_code_variable_assignment(self, mock_invocation_context: InvocationContext):
75-
executor = UnsafeLocalCodeExecutor()
76-
code_input = CodeExecutionInput(code='x = 10\nprint(x * 2)')
77-
result = executor.execute_code(mock_invocation_context, code_input)
78-
79-
assert result.stdout == "20\n"
80-
assert result.stderr == ""
81-
82-
def test_execute_code_empty(self, mock_invocation_context: InvocationContext):
83-
executor = UnsafeLocalCodeExecutor()
84-
code_input = CodeExecutionInput(code='')
85-
result = executor.execute_code(mock_invocation_context, code_input)
86-
assert result.stdout == ""
87-
assert result.stderr == ""
43+
def test_init_default(self):
44+
executor = UnsafeLocalCodeExecutor()
45+
assert not executor.stateful
46+
assert not executor.optimize_data_file
47+
48+
def test_init_stateful_raises_error(self):
49+
with pytest.raises(
50+
ValueError,
51+
match="Cannot set `stateful=True` in UnsafeLocalCodeExecutor.",
52+
):
53+
UnsafeLocalCodeExecutor(stateful=True)
54+
55+
def test_init_optimize_data_file_raises_error(self):
56+
with pytest.raises(
57+
ValueError,
58+
match=(
59+
"Cannot set `optimize_data_file=True` in UnsafeLocalCodeExecutor."
60+
),
61+
):
62+
UnsafeLocalCodeExecutor(optimize_data_file=True)
63+
64+
def test_execute_code_simple_print(
65+
self, mock_invocation_context: InvocationContext
66+
):
67+
executor = UnsafeLocalCodeExecutor()
68+
code_input = CodeExecutionInput(code='print("hello world")')
69+
result = executor.execute_code(mock_invocation_context, code_input)
70+
71+
assert isinstance(result, CodeExecutionResult)
72+
assert result.stdout == "hello world\n"
73+
assert result.stderr == ""
74+
assert result.output_files == []
75+
76+
def test_execute_code_with_error(
77+
self, mock_invocation_context: InvocationContext
78+
):
79+
executor = UnsafeLocalCodeExecutor()
80+
code_input = CodeExecutionInput(code='raise ValueError("Test error")')
81+
result = executor.execute_code(mock_invocation_context, code_input)
82+
83+
assert isinstance(result, CodeExecutionResult)
84+
assert result.stdout == ""
85+
assert "Test error" in result.stderr
86+
assert result.output_files == []
87+
88+
def test_execute_code_variable_assignment(
89+
self, mock_invocation_context: InvocationContext
90+
):
91+
executor = UnsafeLocalCodeExecutor()
92+
code_input = CodeExecutionInput(code="x = 10\nprint(x * 2)")
93+
result = executor.execute_code(mock_invocation_context, code_input)
94+
95+
assert result.stdout == "20\n"
96+
assert result.stderr == ""
97+
98+
def test_execute_code_empty(self, mock_invocation_context: InvocationContext):
99+
executor = UnsafeLocalCodeExecutor()
100+
code_input = CodeExecutionInput(code="")
101+
result = executor.execute_code(mock_invocation_context, code_input)
102+
assert result.stdout == ""
103+
assert result.stderr == ""

0 commit comments

Comments
 (0)
0