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
@ -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(
|
||||
@ -103,7 +104,6 @@ def test_process_llm_request_no_model_name(
|
||||
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,14 +12,16 @@
|
||||
# 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
|
||||
@ -32,7 +34,7 @@ def mock_invocation_context() -> InvocationContext:
|
||||
invocation_id="test_invocation",
|
||||
agent=mock_agent,
|
||||
session=mock_session,
|
||||
session_service=mock_session_service
|
||||
session_service=mock_session_service,
|
||||
)
|
||||
|
||||
|
||||
@ -44,14 +46,24 @@ class TestUnsafeLocalCodeExecutor:
|
||||
assert not executor.optimize_data_file
|
||||
|
||||
def test_init_stateful_raises_error(self):
|
||||
with pytest.raises(ValueError, match="Cannot set `stateful=True` in UnsafeLocalCodeExecutor."):
|
||||
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."):
|
||||
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):
|
||||
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)
|
||||
@ -61,7 +73,9 @@ class TestUnsafeLocalCodeExecutor:
|
||||
assert result.stderr == ""
|
||||
assert result.output_files == []
|
||||
|
||||
def test_execute_code_with_error(self, mock_invocation_context: InvocationContext):
|
||||
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)
|
||||
@ -71,9 +85,11 @@ class TestUnsafeLocalCodeExecutor:
|
||||
assert "Test error" in result.stderr
|
||||
assert result.output_files == []
|
||||
|
||||
def test_execute_code_variable_assignment(self, mock_invocation_context: InvocationContext):
|
||||
def test_execute_code_variable_assignment(
|
||||
self, mock_invocation_context: InvocationContext
|
||||
):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code='x = 10\nprint(x * 2)')
|
||||
code_input = CodeExecutionInput(code="x = 10\nprint(x * 2)")
|
||||
result = executor.execute_code(mock_invocation_context, code_input)
|
||||
|
||||
assert result.stdout == "20\n"
|
||||
@ -81,7 +97,7 @@ class TestUnsafeLocalCodeExecutor:
|
||||
|
||||
def test_execute_code_empty(self, mock_invocation_context: InvocationContext):
|
||||
executor = UnsafeLocalCodeExecutor()
|
||||
code_input = CodeExecutionInput(code='')
|
||||
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