mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-13 23:17:35 -06:00
chore: auto-format files.
PiperOrigin-RevId: 764980009
This commit is contained in:
parent
face2e8cf2
commit
4214c7eddd
@ -59,14 +59,14 @@ class HelpfulCommand(click.Command):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _format_missing_arg_error(click_exception):
|
||||
"""Format the missing argument error with uppercase parameter name.
|
||||
|
||||
|
||||
Args:
|
||||
click_exception: The MissingParameter exception from Click.
|
||||
|
||||
|
||||
Returns:
|
||||
str: Formatted error message with uppercase parameter name.
|
||||
"""
|
||||
|
@ -18,9 +18,9 @@ from .tool_context import ToolContext
|
||||
def transfer_to_agent(agent_name: str, tool_context: ToolContext):
|
||||
"""Transfer the question to another agent.
|
||||
|
||||
This tool hands off control to another agent when it's more suitable to
|
||||
This tool hands off control to another agent when it's more suitable to
|
||||
answer the user's question according to the agent's description.
|
||||
|
||||
|
||||
Args:
|
||||
agent_name: the agent name to transfer to.
|
||||
"""
|
||||
|
@ -11,11 +11,11 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import pytest
|
||||
from google.genai import types
|
||||
|
||||
from google.adk.code_executors.built_in_code_executor import BuiltInCodeExecutor
|
||||
from google.adk.models.llm_request import LlmRequest
|
||||
from google.genai import types
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -78,9 +78,10 @@ def test_process_llm_request_gemini_2_model_with_existing_tools(
|
||||
built_in_executor.process_llm_request(llm_request)
|
||||
assert len(llm_request.config.tools) == 2
|
||||
assert existing_tool in llm_request.config.tools
|
||||
assert types.Tool(
|
||||
code_execution=types.ToolCodeExecution()
|
||||
) in llm_request.config.tools
|
||||
assert (
|
||||
types.Tool(code_execution=types.ToolCodeExecution())
|
||||
in llm_request.config.tools
|
||||
)
|
||||
|
||||
|
||||
def test_process_llm_request_non_gemini_2_model(
|
||||
@ -100,10 +101,9 @@ def test_process_llm_request_no_model_name(
|
||||
built_in_executor: BuiltInCodeExecutor,
|
||||
):
|
||||
"""Tests that a ValueError is raised if model name is not set."""
|
||||
llm_request = LlmRequest() # Model name defaults to None
|
||||
llm_request = LlmRequest() # Model name defaults to None
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
built_in_executor.process_llm_request(llm_request)
|
||||
assert (
|
||||
"Gemini code execution tool is not supported for model None"
|
||||
in str(excinfo.value)
|
||||
)
|
||||
assert "Gemini code execution tool is not supported for model None" in str(
|
||||
excinfo.value
|
||||
)
|
||||
|
@ -12,76 +12,92 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
from google.adk.code_executors.unsafe_local_code_executor import UnsafeLocalCodeExecutor
|
||||
from google.adk.code_executors.code_execution_utils import CodeExecutionInput, CodeExecutionResult
|
||||
from google.adk.agents.invocation_context import InvocationContext
|
||||
|
||||
from google.adk.agents.base_agent import BaseAgent
|
||||
from google.adk.sessions.session import Session
|
||||
from google.adk.agents.invocation_context import InvocationContext
|
||||
from google.adk.code_executors.code_execution_utils import CodeExecutionInput
|
||||
from google.adk.code_executors.code_execution_utils import CodeExecutionResult
|
||||
from google.adk.code_executors.unsafe_local_code_executor import UnsafeLocalCodeExecutor
|
||||
from google.adk.sessions.base_session_service import BaseSessionService
|
||||
from google.adk.sessions.session import Session
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_invocation_context() -> InvocationContext:
|
||||
"""Provides a mock InvocationContext."""
|
||||
mock_agent = MagicMock(spec=BaseAgent)
|
||||
mock_session = MagicMock(spec=Session)
|
||||
mock_session_service = MagicMock(spec=BaseSessionService)
|
||||
return InvocationContext(
|
||||
invocation_id="test_invocation",
|
||||
agent=mock_agent,
|
||||
session=mock_session,
|
||||
session_service=mock_session_service
|
||||
)
|
||||
"""Provides a mock InvocationContext."""
|
||||
mock_agent = MagicMock(spec=BaseAgent)
|
||||
mock_session = MagicMock(spec=Session)
|
||||
mock_session_service = MagicMock(spec=BaseSessionService)
|
||||
return InvocationContext(
|
||||
invocation_id="test_invocation",
|
||||
agent=mock_agent,
|
||||
session=mock_session,
|
||||
session_service=mock_session_service,
|
||||
)
|
||||
|
||||
|
||||
class TestUnsafeLocalCodeExecutor:
|
||||
|
||||
def test_init_default(self):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
assert not executor.stateful
|
||||
assert not executor.optimize_data_file
|
||||
def test_init_default(self):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
assert not executor.stateful
|
||||
assert not executor.optimize_data_file
|
||||
|
||||
def test_init_stateful_raises_error(self):
|
||||
with pytest.raises(ValueError, match="Cannot set `stateful=True` in UnsafeLocalCodeExecutor."):
|
||||
UnsafeLocalCodeExecutor(stateful=True)
|
||||
def test_init_stateful_raises_error(self):
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match="Cannot set `stateful=True` in UnsafeLocalCodeExecutor.",
|
||||
):
|
||||
UnsafeLocalCodeExecutor(stateful=True)
|
||||
|
||||
def test_init_optimize_data_file_raises_error(self):
|
||||
with pytest.raises(ValueError, match="Cannot set `optimize_data_file=True` in UnsafeLocalCodeExecutor."):
|
||||
UnsafeLocalCodeExecutor(optimize_data_file=True)
|
||||
def test_init_optimize_data_file_raises_error(self):
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match=(
|
||||
"Cannot set `optimize_data_file=True` in UnsafeLocalCodeExecutor."
|
||||
),
|
||||
):
|
||||
UnsafeLocalCodeExecutor(optimize_data_file=True)
|
||||
|
||||
def test_execute_code_simple_print(self, mock_invocation_context: InvocationContext):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code='print("hello world")')
|
||||
result = executor.execute_code(mock_invocation_context, code_input)
|
||||
def test_execute_code_simple_print(
|
||||
self, mock_invocation_context: InvocationContext
|
||||
):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code='print("hello world")')
|
||||
result = executor.execute_code(mock_invocation_context, code_input)
|
||||
|
||||
assert isinstance(result, CodeExecutionResult)
|
||||
assert result.stdout == "hello world\n"
|
||||
assert result.stderr == ""
|
||||
assert result.output_files == []
|
||||
assert isinstance(result, CodeExecutionResult)
|
||||
assert result.stdout == "hello world\n"
|
||||
assert result.stderr == ""
|
||||
assert result.output_files == []
|
||||
|
||||
def test_execute_code_with_error(self, mock_invocation_context: InvocationContext):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code='raise ValueError("Test error")')
|
||||
result = executor.execute_code(mock_invocation_context, code_input)
|
||||
def test_execute_code_with_error(
|
||||
self, mock_invocation_context: InvocationContext
|
||||
):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code='raise ValueError("Test error")')
|
||||
result = executor.execute_code(mock_invocation_context, code_input)
|
||||
|
||||
assert isinstance(result, CodeExecutionResult)
|
||||
assert result.stdout == ""
|
||||
assert "Test error" in result.stderr
|
||||
assert result.output_files == []
|
||||
assert isinstance(result, CodeExecutionResult)
|
||||
assert result.stdout == ""
|
||||
assert "Test error" in result.stderr
|
||||
assert result.output_files == []
|
||||
|
||||
def test_execute_code_variable_assignment(self, mock_invocation_context: InvocationContext):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code='x = 10\nprint(x * 2)')
|
||||
result = executor.execute_code(mock_invocation_context, code_input)
|
||||
def test_execute_code_variable_assignment(
|
||||
self, mock_invocation_context: InvocationContext
|
||||
):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code="x = 10\nprint(x * 2)")
|
||||
result = executor.execute_code(mock_invocation_context, code_input)
|
||||
|
||||
assert result.stdout == "20\n"
|
||||
assert result.stderr == ""
|
||||
assert result.stdout == "20\n"
|
||||
assert result.stderr == ""
|
||||
|
||||
def test_execute_code_empty(self, mock_invocation_context: InvocationContext):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code='')
|
||||
result = executor.execute_code(mock_invocation_context, code_input)
|
||||
assert result.stdout == ""
|
||||
assert result.stderr == ""
|
||||
def test_execute_code_empty(self, mock_invocation_context: InvocationContext):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code="")
|
||||
result = executor.execute_code(mock_invocation_context, code_input)
|
||||
assert result.stdout == ""
|
||||
assert result.stderr == ""
|
||||
|
Loading…
Reference in New Issue
Block a user