diff --git a/tests/unittests/agents/test_live_request_queue.py b/tests/unittests/agents/test_live_request_queue.py new file mode 100644 index 0000000..2827100 --- /dev/null +++ b/tests/unittests/agents/test_live_request_queue.py @@ -0,0 +1,52 @@ +import pytest +from unittest.mock import MagicMock, AsyncMock, patch +from google.adk.agents.live_request_queue import LiveRequest, LiveRequestQueue +from google.genai import types + + +@pytest.mark.asyncio +async def test_close_queue(): + queue = LiveRequestQueue() + + with patch.object(queue._queue, "put_nowait") as mock_put_nowait: + queue.close() + mock_put_nowait.assert_called_once_with(LiveRequest(close=True)) + + +def test_send_content(): + queue = LiveRequestQueue() + content = MagicMock(spec=types.Content) + + with patch.object(queue._queue, "put_nowait") as mock_put_nowait: + queue.send_content(content) + mock_put_nowait.assert_called_once_with(LiveRequest(content=content)) + + +def test_send_realtime(): + queue = LiveRequestQueue() + blob = MagicMock(spec=types.Blob) + + with patch.object(queue._queue, "put_nowait") as mock_put_nowait: + queue.send_realtime(blob) + mock_put_nowait.assert_called_once_with(LiveRequest(blob=blob)) + + +def test_send(): + queue = LiveRequestQueue() + req = LiveRequest(content=MagicMock(spec=types.Content)) + + with patch.object(queue._queue, "put_nowait") as mock_put_nowait: + queue.send(req) + mock_put_nowait.assert_called_once_with(req) + + +@pytest.mark.asyncio +async def test_get(): + queue = LiveRequestQueue() + res = MagicMock(spec=types.Content) + + with patch.object(queue._queue, "get", return_value=res) as mock_get: + result = await queue.get() + + assert result == res + mock_get.assert_called_once() diff --git a/tests/unittests/agents/test_readonly_context.py b/tests/unittests/agents/test_readonly_context.py new file mode 100644 index 0000000..8068b6f --- /dev/null +++ b/tests/unittests/agents/test_readonly_context.py @@ -0,0 +1,33 @@ +import pytest +from unittest.mock import MagicMock +from types import MappingProxyType +from google.adk.agents.readonly_context import ReadonlyContext + + +@pytest.fixture +def mock_invocation_context(): + mock_context = MagicMock() + mock_context.invocation_id = "test-invocation-id" + mock_context.agent.name = "test-agent-name" + mock_context.session.state = {"key1": "value1", "key2": "value2"} + + return mock_context + + +def test_invocation_id(mock_invocation_context): + readonly_context = ReadonlyContext(mock_invocation_context) + assert readonly_context.invocation_id == "test-invocation-id" + + +def test_agent_name(mock_invocation_context): + readonly_context = ReadonlyContext(mock_invocation_context) + assert readonly_context.agent_name == "test-agent-name" + + +def test_state_content(mock_invocation_context): + readonly_context = ReadonlyContext(mock_invocation_context) + state = readonly_context.state + + assert isinstance(state, MappingProxyType) + assert state["key1"] == "value1" + assert state["key2"] == "value2" diff --git a/tests/unittests/agents/test_run_config.py b/tests/unittests/agents/test_run_config.py new file mode 100644 index 0000000..7bfb9ce --- /dev/null +++ b/tests/unittests/agents/test_run_config.py @@ -0,0 +1,31 @@ +import pytest +import sys +import logging +from unittest.mock import patch, ANY +from google.adk.agents.run_config import RunConfig + + +def test_validate_max_llm_calls_valid(): + value = RunConfig.validate_max_llm_calls(100) + assert value == 100 + + +def test_validate_max_llm_calls_negative(): + with patch("google.adk.agents.run_config.logger.warning") as mock_warning: + value = RunConfig.validate_max_llm_calls(-1) + mock_warning.assert_called_once_with(ANY) + assert value == -1 + + +def test_validate_max_llm_calls_warns_on_zero(): + with patch("google.adk.agents.run_config.logger.warning") as mock_warning: + value = RunConfig.validate_max_llm_calls(0) + mock_warning.assert_called_once_with(ANY) + assert value == 0 + + +def test_validate_max_llm_calls_too_large(): + with pytest.raises( + ValueError, match=f"max_llm_calls should be less than {sys.maxsize}." + ): + RunConfig.validate_max_llm_calls(sys.maxsize)