You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
test: Add unit tests for the App class and improve Runner initialization tests
- Added `tests/unittests/apps/test_apps.py` with basic tests for `App` initialization. - Modified `tests/unittests/test_runners.py` to include a test that verifies `Runner` raises a `ValueError` when both `app` and `app_name` are provided during initialization. PiperOrigin-RevId: 803556826
This commit is contained in:
committed by
Copybara-Service
parent
decc19b188
commit
fc90ce968f
@@ -0,0 +1,13 @@
|
||||
# Copyright 2025 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# 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.
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright 2025 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# 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.
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
from google.adk.agents.base_agent import BaseAgent
|
||||
from google.adk.apps.app import App
|
||||
from google.adk.plugins.base_plugin import BasePlugin
|
||||
|
||||
|
||||
class TestApp:
|
||||
"""Tests for App class."""
|
||||
|
||||
def test_app_initialization(self):
|
||||
"""Test that the app is initialized correctly without plugins."""
|
||||
mock_agent = Mock(spec=BaseAgent)
|
||||
app = App(name="test_app", root_agent=mock_agent)
|
||||
assert app.name == "test_app"
|
||||
assert app.root_agent == mock_agent
|
||||
assert app.plugins == []
|
||||
|
||||
def test_app_initialization_with_plugins(self):
|
||||
"""Test that the app is initialized correctly with plugins."""
|
||||
mock_agent = Mock(spec=BaseAgent)
|
||||
mock_plugin = Mock(spec=BasePlugin)
|
||||
app = App(name="test_app", root_agent=mock_agent, plugins=[mock_plugin])
|
||||
assert app.name == "test_app"
|
||||
assert app.root_agent == mock_agent
|
||||
assert app.plugins == [mock_plugin]
|
||||
@@ -17,6 +17,7 @@ from typing import Optional
|
||||
from google.adk.agents.base_agent import BaseAgent
|
||||
from google.adk.agents.invocation_context import InvocationContext
|
||||
from google.adk.agents.llm_agent import LlmAgent
|
||||
from google.adk.apps.app import App
|
||||
from google.adk.artifacts.in_memory_artifact_service import InMemoryArtifactService
|
||||
from google.adk.events.event import Event
|
||||
from google.adk.plugins.base_plugin import BasePlugin
|
||||
@@ -427,6 +428,20 @@ class TestRunnerWithPlugins:
|
||||
|
||||
assert modified_event_message == MockPlugin.ON_EVENT_CALLBACK_MSG
|
||||
|
||||
def test_runner_init_raises_error_with_app_and_app_name_and_agent(self):
|
||||
"""Test that ValueError is raised when app, app_name and agent are provided."""
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match="When app is provided, app_name should not be provided.",
|
||||
):
|
||||
Runner(
|
||||
app=App(name="test_app", root_agent=self.root_agent),
|
||||
app_name="test_app",
|
||||
agent=self.root_agent,
|
||||
session_service=self.session_service,
|
||||
artifact_service=self.artifact_service,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__])
|
||||
|
||||
Reference in New Issue
Block a user