diff --git a/tests/unittests/apps/__init__.py b/tests/unittests/apps/__init__.py new file mode 100644 index 00000000..0a2669d7 --- /dev/null +++ b/tests/unittests/apps/__init__.py @@ -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. diff --git a/tests/unittests/apps/test_apps.py b/tests/unittests/apps/test_apps.py new file mode 100644 index 00000000..76c72808 --- /dev/null +++ b/tests/unittests/apps/test_apps.py @@ -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] diff --git a/tests/unittests/test_runners.py b/tests/unittests/test_runners.py index 61ee4b01..46902481 100644 --- a/tests/unittests/test_runners.py +++ b/tests/unittests/test_runners.py @@ -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__])