Move public_utils to utils in tests

Renamed conflicting utils.py as testing_utils.py

PiperOrigin-RevId: 761715808
This commit is contained in:
Selcuk Gun
2025-05-21 16:34:28 -07:00
committed by Copybara-Service
parent 09cb128cf9
commit 41b33d4a0a
22 changed files with 236 additions and 208 deletions

View File

@@ -17,7 +17,7 @@ from google.adk.tools.function_tool import FunctionTool
from google.adk.tools.retrieval.vertex_ai_rag_retrieval import VertexAiRagRetrieval
from google.genai import types
from ... import utils
from ... import testing_utils
def noop_tool(x: str) -> str:
@@ -28,7 +28,7 @@ def test_vertex_rag_retrieval_for_gemini_1_x():
responses = [
'response1',
]
mockModel = utils.MockModel.create(responses=responses)
mockModel = testing_utils.MockModel.create(responses=responses)
mockModel.model = 'gemini-1.5-pro'
# Calls the first time.
@@ -45,12 +45,12 @@ def test_vertex_rag_retrieval_for_gemini_1_x():
)
],
)
runner = utils.InMemoryRunner(agent)
runner = testing_utils.InMemoryRunner(agent)
events = runner.run('test1')
# Asserts the requests.
assert len(mockModel.requests) == 1
assert utils.simplify_contents(mockModel.requests[0].contents) == [
assert testing_utils.simplify_contents(mockModel.requests[0].contents) == [
('user', 'test1'),
]
assert len(mockModel.requests[0].config.tools) == 1
@@ -65,7 +65,7 @@ def test_vertex_rag_retrieval_for_gemini_1_x_with_another_function_tool():
responses = [
'response1',
]
mockModel = utils.MockModel.create(responses=responses)
mockModel = testing_utils.MockModel.create(responses=responses)
mockModel.model = 'gemini-1.5-pro'
# Calls the first time.
@@ -83,12 +83,12 @@ def test_vertex_rag_retrieval_for_gemini_1_x_with_another_function_tool():
FunctionTool(func=noop_tool),
],
)
runner = utils.InMemoryRunner(agent)
runner = testing_utils.InMemoryRunner(agent)
events = runner.run('test1')
# Asserts the requests.
assert len(mockModel.requests) == 1
assert utils.simplify_contents(mockModel.requests[0].contents) == [
assert testing_utils.simplify_contents(mockModel.requests[0].contents) == [
('user', 'test1'),
]
assert len(mockModel.requests[0].config.tools[0].function_declarations) == 2
@@ -107,7 +107,7 @@ def test_vertex_rag_retrieval_for_gemini_2_x():
responses = [
'response1',
]
mockModel = utils.MockModel.create(responses=responses)
mockModel = testing_utils.MockModel.create(responses=responses)
mockModel.model = 'gemini-2.0-flash'
# Calls the first time.
@@ -124,12 +124,12 @@ def test_vertex_rag_retrieval_for_gemini_2_x():
)
],
)
runner = utils.InMemoryRunner(agent)
runner = testing_utils.InMemoryRunner(agent)
events = runner.run('test1')
# Asserts the requests.
assert len(mockModel.requests) == 1
assert utils.simplify_contents(mockModel.requests[0].contents) == [
assert testing_utils.simplify_contents(mockModel.requests[0].contents) == [
('user', 'test1'),
]
assert len(mockModel.requests[0].config.tools) == 1

View File

@@ -20,7 +20,7 @@ from pydantic import BaseModel
import pytest
from pytest import mark
from .. import utils
from .. import testing_utils
pytestmark = pytest.mark.skip(
reason='Skipping until tool.func evaluations are fixed (async)'
@@ -50,7 +50,7 @@ def change_state_callback(callback_context: CallbackContext):
def test_no_schema():
mock_model = utils.MockModel.create(
mock_model = testing_utils.MockModel.create(
responses=[
function_call_no_schema,
'response1',
@@ -69,9 +69,9 @@ def test_no_schema():
tools=[AgentTool(agent=tool_agent)],
)
runner = utils.InMemoryRunner(root_agent)
runner = testing_utils.InMemoryRunner(root_agent)
assert utils.simplify_events(runner.run('test1')) == [
assert testing_utils.simplify_events(runner.run('test1')) == [
('root_agent', function_call_no_schema),
('root_agent', function_response_no_schema),
('root_agent', 'response2'),
@@ -81,7 +81,7 @@ def test_no_schema():
def test_update_state():
"""The agent tool can read and change parent state."""
mock_model = utils.MockModel.create(
mock_model = testing_utils.MockModel.create(
responses=[
function_call_no_schema,
'{"custom_output": "response1"}',
@@ -102,7 +102,7 @@ def test_update_state():
tools=[AgentTool(agent=tool_agent)],
)
runner = utils.InMemoryRunner(root_agent)
runner = testing_utils.InMemoryRunner(root_agent)
runner.session.state['state_1'] = 'state1_value'
runner.run('test1')
@@ -128,7 +128,7 @@ def test_custom_schema():
class CustomOutput(BaseModel):
custom_output: str
mock_model = utils.MockModel.create(
mock_model = testing_utils.MockModel.create(
responses=[
function_call_custom,
'{"custom_output": "response1"}',
@@ -150,10 +150,10 @@ def test_custom_schema():
tools=[AgentTool(agent=tool_agent)],
)
runner = utils.InMemoryRunner(root_agent)
runner = testing_utils.InMemoryRunner(root_agent)
runner.session.state['state_1'] = 'state1_value'
assert utils.simplify_events(runner.run('test1')) == [
assert testing_utils.simplify_events(runner.run('test1')) == [
('root_agent', function_call_custom),
('root_agent', function_response_custom),
('root_agent', 'response2'),