mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
chore: Drop Python 3.9 support, set minimum to Python 3.10
Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 839799108
This commit is contained in:
committed by
Copybara-Service
parent
e02b9fb608
commit
8c9105bf14
@@ -12,50 +12,33 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from a2a.types import DataPart
|
||||
from a2a.types import Message
|
||||
from a2a.types import Role
|
||||
from a2a.types import Task
|
||||
from a2a.types import TaskState
|
||||
from a2a.types import TaskStatusUpdateEvent
|
||||
from google.adk.a2a.converters.event_converter import _create_artifact_id
|
||||
from google.adk.a2a.converters.event_converter import _create_error_status_event
|
||||
from google.adk.a2a.converters.event_converter import _create_status_update_event
|
||||
from google.adk.a2a.converters.event_converter import _get_adk_metadata_key
|
||||
from google.adk.a2a.converters.event_converter import _get_context_metadata
|
||||
from google.adk.a2a.converters.event_converter import _process_long_running_tool
|
||||
from google.adk.a2a.converters.event_converter import _serialize_metadata_value
|
||||
from google.adk.a2a.converters.event_converter import ARTIFACT_ID_SEPARATOR
|
||||
from google.adk.a2a.converters.event_converter import convert_a2a_task_to_event
|
||||
from google.adk.a2a.converters.event_converter import convert_event_to_a2a_events
|
||||
from google.adk.a2a.converters.event_converter import convert_event_to_a2a_message
|
||||
from google.adk.a2a.converters.event_converter import DEFAULT_ERROR_MESSAGE
|
||||
from google.adk.a2a.converters.utils import ADK_METADATA_KEY_PREFIX
|
||||
from google.adk.agents.invocation_context import InvocationContext
|
||||
from google.adk.events.event import Event
|
||||
from google.adk.events.event_actions import EventActions
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from a2a.types import DataPart
|
||||
from a2a.types import Message
|
||||
from a2a.types import Role
|
||||
from a2a.types import Task
|
||||
from a2a.types import TaskState
|
||||
from a2a.types import TaskStatusUpdateEvent
|
||||
from google.adk.a2a.converters.event_converter import _create_artifact_id
|
||||
from google.adk.a2a.converters.event_converter import _create_error_status_event
|
||||
from google.adk.a2a.converters.event_converter import _create_status_update_event
|
||||
from google.adk.a2a.converters.event_converter import _get_adk_metadata_key
|
||||
from google.adk.a2a.converters.event_converter import _get_context_metadata
|
||||
from google.adk.a2a.converters.event_converter import _process_long_running_tool
|
||||
from google.adk.a2a.converters.event_converter import _serialize_metadata_value
|
||||
from google.adk.a2a.converters.event_converter import ARTIFACT_ID_SEPARATOR
|
||||
from google.adk.a2a.converters.event_converter import convert_a2a_task_to_event
|
||||
from google.adk.a2a.converters.event_converter import convert_event_to_a2a_events
|
||||
from google.adk.a2a.converters.event_converter import convert_event_to_a2a_message
|
||||
from google.adk.a2a.converters.event_converter import DEFAULT_ERROR_MESSAGE
|
||||
from google.adk.a2a.converters.utils import ADK_METADATA_KEY_PREFIX
|
||||
from google.adk.agents.invocation_context import InvocationContext
|
||||
from google.adk.events.event import Event
|
||||
from google.adk.events.event_actions import EventActions
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Imports are not needed since tests will be skipped due to pytestmark.
|
||||
# The imported names are only used within test methods, not at module level,
|
||||
# so no NameError occurs during module compilation.
|
||||
pass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
class TestEventConverter:
|
||||
"""Test suite for event_converter module."""
|
||||
|
||||
@@ -13,38 +13,21 @@
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import sys
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from a2a import types as a2a_types
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_CODE_EXECUTION_RESULT
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_EXECUTABLE_CODE
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_KEY
|
||||
from google.adk.a2a.converters.part_converter import convert_a2a_part_to_genai_part
|
||||
from google.adk.a2a.converters.part_converter import convert_genai_part_to_a2a_part
|
||||
from google.adk.a2a.converters.utils import _get_adk_metadata_key
|
||||
from google.genai import types as genai_types
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from a2a import types as a2a_types
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_CODE_EXECUTION_RESULT
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_EXECUTABLE_CODE
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE
|
||||
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_KEY
|
||||
from google.adk.a2a.converters.part_converter import convert_a2a_part_to_genai_part
|
||||
from google.adk.a2a.converters.part_converter import convert_genai_part_to_a2a_part
|
||||
from google.adk.a2a.converters.utils import _get_adk_metadata_key
|
||||
from google.genai import types as genai_types
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Imports are not needed since tests will be skipped due to pytestmark.
|
||||
# The imported names are only used within test methods, not at module level,
|
||||
# so no NameError occurs during module compilation.
|
||||
pass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
class TestConvertA2aPartToGenaiPart:
|
||||
"""Test cases for convert_a2a_part_to_genai_part function."""
|
||||
|
||||
@@ -12,33 +12,16 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from a2a.server.agent_execution import RequestContext
|
||||
from google.adk.a2a.converters.request_converter import _get_user_id
|
||||
from google.adk.a2a.converters.request_converter import convert_a2a_request_to_agent_run_request
|
||||
from google.adk.runners import RunConfig
|
||||
from google.genai import types as genai_types
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from a2a.server.agent_execution import RequestContext
|
||||
from google.adk.a2a.converters.request_converter import _get_user_id
|
||||
from google.adk.a2a.converters.request_converter import convert_a2a_request_to_agent_run_request
|
||||
from google.adk.runners import RunConfig
|
||||
from google.genai import types as genai_types
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Imports are not needed since tests will be skipped due to pytestmark.
|
||||
# The imported names are only used within test methods, not at module level,
|
||||
# so no NameError occurs during module compilation.
|
||||
pass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
class TestGetUserId:
|
||||
"""Test cases for _get_user_id function."""
|
||||
|
||||
@@ -12,31 +12,13 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from google.adk.a2a.converters.utils import _from_a2a_context_id
|
||||
from google.adk.a2a.converters.utils import _get_adk_metadata_key
|
||||
from google.adk.a2a.converters.utils import _to_a2a_context_id
|
||||
from google.adk.a2a.converters.utils import ADK_CONTEXT_ID_PREFIX
|
||||
from google.adk.a2a.converters.utils import ADK_METADATA_KEY_PREFIX
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from google.adk.a2a.converters.utils import _from_a2a_context_id
|
||||
from google.adk.a2a.converters.utils import _get_adk_metadata_key
|
||||
from google.adk.a2a.converters.utils import _to_a2a_context_id
|
||||
from google.adk.a2a.converters.utils import ADK_CONTEXT_ID_PREFIX
|
||||
from google.adk.a2a.converters.utils import ADK_METADATA_KEY_PREFIX
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Imports are not needed since tests will be skipped due to pytestmark.
|
||||
# The imported names are only used within test methods, not at module level,
|
||||
# so no NameError occurs during module compilation.
|
||||
pass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
class TestUtilsFunctions:
|
||||
"""Test suite for utils module functions."""
|
||||
|
||||
@@ -12,41 +12,24 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from a2a.server.agent_execution.context import RequestContext
|
||||
from a2a.server.events.event_queue import EventQueue
|
||||
from a2a.types import Message
|
||||
from a2a.types import TaskState
|
||||
from a2a.types import TextPart
|
||||
from google.adk.a2a.converters.request_converter import AgentRunRequest
|
||||
from google.adk.a2a.executor.a2a_agent_executor import A2aAgentExecutor
|
||||
from google.adk.a2a.executor.a2a_agent_executor import A2aAgentExecutorConfig
|
||||
from google.adk.events.event import Event
|
||||
from google.adk.runners import RunConfig
|
||||
from google.adk.runners import Runner
|
||||
from google.genai.types import Content
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from a2a.server.agent_execution.context import RequestContext
|
||||
from a2a.server.events.event_queue import EventQueue
|
||||
from a2a.types import Message
|
||||
from a2a.types import TaskState
|
||||
from a2a.types import TextPart
|
||||
from google.adk.a2a.converters.request_converter import AgentRunRequest
|
||||
from google.adk.a2a.executor.a2a_agent_executor import A2aAgentExecutor
|
||||
from google.adk.a2a.executor.a2a_agent_executor import A2aAgentExecutorConfig
|
||||
from google.adk.events.event import Event
|
||||
from google.adk.runners import RunConfig
|
||||
from google.adk.runners import Runner
|
||||
from google.genai.types import Content
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Imports are not needed since tests will be skipped due to pytestmark.
|
||||
# The imported names are only used within test methods, not at module level,
|
||||
# so no NameError occurs during module compilation.
|
||||
pass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
class TestA2aAgentExecutor:
|
||||
"""Test suite for A2aAgentExecutor class."""
|
||||
|
||||
@@ -12,35 +12,18 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
from unittest.mock import Mock
|
||||
|
||||
from a2a.types import Message
|
||||
from a2a.types import Part
|
||||
from a2a.types import Role
|
||||
from a2a.types import TaskState
|
||||
from a2a.types import TaskStatus
|
||||
from a2a.types import TaskStatusUpdateEvent
|
||||
from a2a.types import TextPart
|
||||
from google.adk.a2a.executor.task_result_aggregator import TaskResultAggregator
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from a2a.types import Message
|
||||
from a2a.types import Part
|
||||
from a2a.types import Role
|
||||
from a2a.types import TaskState
|
||||
from a2a.types import TaskStatus
|
||||
from a2a.types import TaskStatusUpdateEvent
|
||||
from a2a.types import TextPart
|
||||
from google.adk.a2a.executor.task_result_aggregator import TaskResultAggregator
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Imports are not needed since tests will be skipped due to pytestmark.
|
||||
# The imported names are only used within test methods, not at module level,
|
||||
# so no NameError occurs during module compilation.
|
||||
pass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
def create_test_message(text: str):
|
||||
"""Helper function to create a test Message object."""
|
||||
|
||||
@@ -12,55 +12,38 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from a2a.types import AgentCapabilities
|
||||
from a2a.types import AgentCard
|
||||
from a2a.types import AgentProvider
|
||||
from a2a.types import AgentSkill
|
||||
from a2a.types import SecurityScheme
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_agent_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_llm_agent_description_with_instructions
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_loop_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_orchestration_skill
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_parallel_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_sequential_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _convert_example_tool_examples
|
||||
from google.adk.a2a.utils.agent_card_builder import _extract_examples_from_instruction
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_agent_skill_name
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_agent_type
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_default_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_input_modes
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_output_modes
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_workflow_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _replace_pronouns
|
||||
from google.adk.a2a.utils.agent_card_builder import AgentCardBuilder
|
||||
from google.adk.agents.base_agent import BaseAgent
|
||||
from google.adk.agents.llm_agent import LlmAgent
|
||||
from google.adk.agents.loop_agent import LoopAgent
|
||||
from google.adk.agents.parallel_agent import ParallelAgent
|
||||
from google.adk.agents.sequential_agent import SequentialAgent
|
||||
from google.adk.tools.example_tool import ExampleTool
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from a2a.types import AgentCapabilities
|
||||
from a2a.types import AgentCard
|
||||
from a2a.types import AgentProvider
|
||||
from a2a.types import AgentSkill
|
||||
from a2a.types import SecurityScheme
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_agent_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_llm_agent_description_with_instructions
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_loop_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_orchestration_skill
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_parallel_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _build_sequential_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _convert_example_tool_examples
|
||||
from google.adk.a2a.utils.agent_card_builder import _extract_examples_from_instruction
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_agent_skill_name
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_agent_type
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_default_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_input_modes
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_output_modes
|
||||
from google.adk.a2a.utils.agent_card_builder import _get_workflow_description
|
||||
from google.adk.a2a.utils.agent_card_builder import _replace_pronouns
|
||||
from google.adk.a2a.utils.agent_card_builder import AgentCardBuilder
|
||||
from google.adk.agents.base_agent import BaseAgent
|
||||
from google.adk.agents.llm_agent import LlmAgent
|
||||
from google.adk.agents.loop_agent import LoopAgent
|
||||
from google.adk.agents.parallel_agent import ParallelAgent
|
||||
from google.adk.agents.sequential_agent import SequentialAgent
|
||||
from google.adk.tools.example_tool import ExampleTool
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Imports are not needed since tests will be skipped due to pytestmark.
|
||||
# The imported names are only used within test methods, not at module level,
|
||||
# so no NameError occurs during module compilation.
|
||||
pass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
class TestAgentCardBuilder:
|
||||
"""Test suite for AgentCardBuilder class."""
|
||||
|
||||
@@ -12,42 +12,25 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from a2a.server.apps import A2AStarletteApplication
|
||||
from a2a.server.request_handlers import DefaultRequestHandler
|
||||
from a2a.server.tasks import InMemoryTaskStore
|
||||
from a2a.types import AgentCard
|
||||
from google.adk.a2a.executor.a2a_agent_executor import A2aAgentExecutor
|
||||
from google.adk.a2a.utils.agent_card_builder import AgentCardBuilder
|
||||
from google.adk.a2a.utils.agent_to_a2a import to_a2a
|
||||
from google.adk.agents.base_agent import BaseAgent
|
||||
from google.adk.artifacts.in_memory_artifact_service import InMemoryArtifactService
|
||||
from google.adk.auth.credential_service.in_memory_credential_service import InMemoryCredentialService
|
||||
from google.adk.memory.in_memory_memory_service import InMemoryMemoryService
|
||||
from google.adk.runners import Runner
|
||||
from google.adk.sessions.in_memory_session_service import InMemorySessionService
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from a2a.server.apps import A2AStarletteApplication
|
||||
from a2a.server.request_handlers import DefaultRequestHandler
|
||||
from a2a.server.tasks import InMemoryTaskStore
|
||||
from a2a.types import AgentCard
|
||||
from google.adk.a2a.executor.a2a_agent_executor import A2aAgentExecutor
|
||||
from google.adk.a2a.utils.agent_card_builder import AgentCardBuilder
|
||||
from google.adk.a2a.utils.agent_to_a2a import to_a2a
|
||||
from google.adk.agents.base_agent import BaseAgent
|
||||
from google.adk.artifacts.in_memory_artifact_service import InMemoryArtifactService
|
||||
from google.adk.auth.credential_service.in_memory_credential_service import InMemoryCredentialService
|
||||
from google.adk.memory.in_memory_memory_service import InMemoryMemoryService
|
||||
from google.adk.runners import Runner
|
||||
from google.adk.sessions.in_memory_session_service import InMemorySessionService
|
||||
from starlette.applications import Starlette
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Imports are not needed since tests will be skipped due to pytestmark.
|
||||
# The imported names are only used within test methods, not at module level,
|
||||
# so no NameError occurs during module compilation.
|
||||
pass
|
||||
else:
|
||||
raise e
|
||||
from starlette.applications import Starlette
|
||||
|
||||
|
||||
class TestToA2A:
|
||||
|
||||
@@ -13,34 +13,14 @@
|
||||
# limitations under the License.
|
||||
|
||||
"""Unit tests for McpInstructionProvider."""
|
||||
import sys
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import patch
|
||||
|
||||
from google.adk.agents.mcp_instruction_provider import McpInstructionProvider
|
||||
from google.adk.agents.readonly_context import ReadonlyContext
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10),
|
||||
reason="MCP instruction provider requires Python 3.10+",
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from google.adk.agents.mcp_instruction_provider import McpInstructionProvider
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Create dummy classes to prevent NameError during test collection
|
||||
# Tests will be skipped anyway due to pytestmark
|
||||
class DummyClass:
|
||||
pass
|
||||
|
||||
McpInstructionProvider = DummyClass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
class TestMcpInstructionProvider:
|
||||
"""Unit tests for McpInstructionProvider."""
|
||||
|
||||
@@ -14,70 +14,38 @@
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import tempfile
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import create_autospec
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from a2a.client.client import ClientConfig
|
||||
from a2a.client.client import Consumer
|
||||
from a2a.client.client_factory import ClientFactory
|
||||
from a2a.types import AgentCapabilities
|
||||
from a2a.types import AgentCard
|
||||
from a2a.types import AgentSkill
|
||||
from a2a.types import Artifact
|
||||
from a2a.types import Message as A2AMessage
|
||||
from a2a.types import Part as A2ATaskStatus
|
||||
from a2a.types import SendMessageSuccessResponse
|
||||
from a2a.types import Task as A2ATask
|
||||
from a2a.types import TaskArtifactUpdateEvent
|
||||
from a2a.types import TaskState
|
||||
from a2a.types import TaskStatus
|
||||
from a2a.types import TaskStatusUpdateEvent
|
||||
from a2a.types import TextPart
|
||||
from google.adk.agents.invocation_context import InvocationContext
|
||||
from google.adk.agents.remote_a2a_agent import A2A_METADATA_PREFIX
|
||||
from google.adk.agents.remote_a2a_agent import AgentCardResolutionError
|
||||
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
|
||||
from google.adk.events.event import Event
|
||||
from google.adk.sessions.session import Session
|
||||
from google.genai import types as genai_types
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from a2a.client.client import ClientConfig
|
||||
from a2a.client.client import Consumer
|
||||
from a2a.client.client_factory import ClientFactory
|
||||
from a2a.types import AgentCapabilities
|
||||
from a2a.types import AgentCard
|
||||
from a2a.types import AgentSkill
|
||||
from a2a.types import Artifact
|
||||
from a2a.types import Message as A2AMessage
|
||||
from a2a.types import Part as A2ATaskStatus
|
||||
from a2a.types import SendMessageSuccessResponse
|
||||
from a2a.types import Task as A2ATask
|
||||
from a2a.types import TaskArtifactUpdateEvent
|
||||
from a2a.types import TaskState
|
||||
from a2a.types import TaskStatus
|
||||
from a2a.types import TaskStatusUpdateEvent
|
||||
from a2a.types import TextPart
|
||||
from google.adk.agents.invocation_context import InvocationContext
|
||||
from google.adk.agents.remote_a2a_agent import A2A_METADATA_PREFIX
|
||||
from google.adk.agents.remote_a2a_agent import AgentCardResolutionError
|
||||
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Create dummy classes to prevent NameError during module compilation.
|
||||
# These are needed because the module has type annotations and module-level
|
||||
# helper functions that reference imported types.
|
||||
class DummyTypes:
|
||||
pass
|
||||
|
||||
AgentCapabilities = DummyTypes()
|
||||
AgentCard = DummyTypes()
|
||||
AgentSkill = DummyTypes()
|
||||
A2AMessage = DummyTypes()
|
||||
SendMessageSuccessResponse = DummyTypes()
|
||||
A2ATask = DummyTypes()
|
||||
TaskStatusUpdateEvent = DummyTypes()
|
||||
Artifact = DummyTypes()
|
||||
TaskArtifactUpdateEvent = DummyTypes()
|
||||
InvocationContext = DummyTypes()
|
||||
RemoteA2aAgent = DummyTypes()
|
||||
AgentCardResolutionError = Exception
|
||||
A2A_METADATA_PREFIX = ""
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
# Helper function to create a proper AgentCard for testing
|
||||
def create_test_agent_card(
|
||||
|
||||
@@ -509,8 +509,6 @@ async def create_test_eval_set(
|
||||
@pytest.fixture
|
||||
def temp_agents_dir_with_a2a():
|
||||
"""Create a temporary agents directory with A2A agent configurations for testing."""
|
||||
if sys.version_info < (3, 10):
|
||||
pytest.skip("A2A requires Python 3.10+")
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
# Create test agent directory
|
||||
agent_dir = Path(temp_dir) / "test_a2a_agent"
|
||||
@@ -554,9 +552,6 @@ def test_app_with_a2a(
|
||||
temp_agents_dir_with_a2a,
|
||||
):
|
||||
"""Create a TestClient for the FastAPI app with A2A enabled."""
|
||||
if sys.version_info < (3, 10):
|
||||
pytest.skip("A2A requires Python 3.10+")
|
||||
|
||||
# Mock A2A related classes
|
||||
with (
|
||||
patch("signal.signal", return_value=None),
|
||||
@@ -1150,9 +1145,6 @@ def test_get_event_graph_returns_dot_src_for_app_agent():
|
||||
assert "dotSrc" in response.json()
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
def test_a2a_agent_discovery(test_app_with_a2a):
|
||||
"""Test that A2A agents are properly discovered and configured."""
|
||||
# This test mainly verifies that the A2A setup doesn't break the app
|
||||
@@ -1161,9 +1153,6 @@ def test_a2a_agent_discovery(test_app_with_a2a):
|
||||
logger.info("A2A agent discovery test passed")
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
|
||||
)
|
||||
def test_a2a_disabled_by_default(test_app):
|
||||
"""Test that A2A functionality is disabled by default."""
|
||||
# The regular test_app fixture has a2a=False
|
||||
|
||||
@@ -536,9 +536,6 @@ def test_generate_final_eval_status_doesn_t_throw_on(eval_service):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+"
|
||||
)
|
||||
async def test_mcp_stdio_agent_no_runtime_error(mocker):
|
||||
"""Test that LocalEvalService can handle MCP stdio agents without RuntimeError.
|
||||
|
||||
|
||||
@@ -57,10 +57,8 @@ class CustomErrorExtractionPlugin(ReflectAndRetryToolPlugin):
|
||||
return None
|
||||
|
||||
|
||||
# Inheriting from IsolatedAsyncioTestCase ensures these tests works in Python
|
||||
# 3.9. See https://github.com/pytest-dev/pytest-asyncio/issues/1039
|
||||
# Without this, the tests will fail with a "RuntimeError: There is no current
|
||||
# event loop in thread 'MainThread'."
|
||||
# Inheriting from IsolatedAsyncioTestCase ensures consistent behavior.
|
||||
# See https://github.com/pytest-dev/pytest-asyncio/issues/1039
|
||||
class TestReflectAndRetryToolPlugin(IsolatedAsyncioTestCase):
|
||||
"""Comprehensive tests for ReflectAndRetryToolPlugin focusing on behavior."""
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ async def test_tracer_start_as_current_span(
|
||||
isinstance(referrer, Aclosing)
|
||||
or isinstance(indirect_referrer, Aclosing)
|
||||
for referrer in gc.get_referrers(coro)
|
||||
# Some coroutines have a layer of indirection in python 3.9 and 3.10
|
||||
# Some coroutines have a layer of indirection in Python 3.10
|
||||
for indirect_referrer in gc.get_referrers(referrer)
|
||||
), f'Coro `{coro.__name__}` is not wrapped with Aclosing'
|
||||
firstiter(coro)
|
||||
|
||||
@@ -47,7 +47,7 @@ class TestComputerUseTool:
|
||||
@pytest.fixture
|
||||
def mock_computer_function(self):
|
||||
"""Fixture providing a mock computer function."""
|
||||
# Create a real async function instead of AsyncMock for Python 3.9 compatibility
|
||||
# Create a real async function instead of AsyncMock for better test control
|
||||
calls = []
|
||||
|
||||
async def mock_func(*args, **kwargs):
|
||||
|
||||
@@ -22,46 +22,14 @@ from unittest.mock import AsyncMock
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import retry_on_errors
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
|
||||
from mcp import StdioServerParameters
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import retry_on_errors
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Create dummy classes to prevent NameError during test collection
|
||||
# Tests will be skipped anyway due to pytestmark
|
||||
class DummyClass:
|
||||
pass
|
||||
|
||||
MCPSessionManager = DummyClass
|
||||
retry_on_errors = lambda x: x
|
||||
SseConnectionParams = DummyClass
|
||||
StdioConnectionParams = DummyClass
|
||||
StreamableHTTPConnectionParams = DummyClass
|
||||
else:
|
||||
raise e
|
||||
|
||||
# Import real MCP classes
|
||||
try:
|
||||
from mcp import StdioServerParameters
|
||||
except ImportError:
|
||||
# Create a mock if MCP is not available
|
||||
class StdioServerParameters:
|
||||
|
||||
def __init__(self, command="test_command", args=None):
|
||||
self.command = command
|
||||
self.args = args or []
|
||||
|
||||
|
||||
class MockClientSession:
|
||||
"""Mock ClientSession for testing."""
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
@@ -23,39 +22,15 @@ from google.adk.auth.auth_credential import HttpAuth
|
||||
from google.adk.auth.auth_credential import HttpCredentials
|
||||
from google.adk.auth.auth_credential import OAuth2Auth
|
||||
from google.adk.auth.auth_credential import ServiceAccount
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
|
||||
from google.adk.tools.mcp_tool.mcp_tool import MCPTool
|
||||
from google.adk.tools.tool_context import ToolContext
|
||||
from google.genai.types import FunctionDeclaration
|
||||
from google.genai.types import Type
|
||||
from mcp.types import CallToolResult
|
||||
from mcp.types import TextContent
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
|
||||
from google.adk.tools.mcp_tool.mcp_tool import MCPTool
|
||||
from google.adk.tools.tool_context import ToolContext
|
||||
from google.genai.types import FunctionDeclaration
|
||||
from google.genai.types import Type
|
||||
from mcp.types import CallToolResult
|
||||
from mcp.types import TextContent
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Create dummy classes to prevent NameError during test collection
|
||||
# Tests will be skipped anyway due to pytestmark
|
||||
class DummyClass:
|
||||
pass
|
||||
|
||||
MCPSessionManager = DummyClass
|
||||
MCPTool = DummyClass
|
||||
ToolContext = DummyClass
|
||||
FunctionDeclaration = DummyClass
|
||||
Type = DummyClass
|
||||
CallToolResult = DummyClass
|
||||
TextContent = DummyClass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
# Mock MCP Tool from mcp.types
|
||||
class MockMCPTool:
|
||||
|
||||
@@ -20,47 +20,17 @@ from unittest.mock import AsyncMock
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from google.adk.agents.readonly_context import ReadonlyContext
|
||||
from google.adk.auth.auth_credential import AuthCredential
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_tool import MCPTool
|
||||
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
|
||||
from mcp import StdioServerParameters
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from google.adk.agents.readonly_context import ReadonlyContext
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
|
||||
from google.adk.tools.mcp_tool.mcp_tool import MCPTool
|
||||
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
|
||||
from mcp import StdioServerParameters
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Create dummy classes to prevent NameError during test collection
|
||||
# Tests will be skipped anyway due to pytestmark
|
||||
class DummyClass:
|
||||
pass
|
||||
|
||||
class StdioServerParameters:
|
||||
|
||||
def __init__(self, command="test_command", args=None):
|
||||
self.command = command
|
||||
self.args = args or []
|
||||
|
||||
MCPSessionManager = DummyClass
|
||||
SseConnectionParams = DummyClass
|
||||
StdioConnectionParams = DummyClass
|
||||
StreamableHTTPConnectionParams = DummyClass
|
||||
MCPTool = DummyClass
|
||||
MCPToolset = DummyClass
|
||||
ReadonlyContext = DummyClass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
class MockMCPTool:
|
||||
"""Mock MCP Tool for testing."""
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
"""Tests for FilesRetrieval tool."""
|
||||
|
||||
import sys
|
||||
import unittest.mock as mock
|
||||
|
||||
from google.adk.tools.retrieval.files_retrieval import _get_default_embedding_model
|
||||
@@ -111,9 +110,6 @@ class TestFilesRetrieval:
|
||||
|
||||
def test_get_default_embedding_model_success(self):
|
||||
"""Test _get_default_embedding_model returns Google embedding when available."""
|
||||
# Skip this test in Python 3.9 where llama_index.embeddings.google_genai may not be available
|
||||
if sys.version_info < (3, 10):
|
||||
pytest.skip("llama_index.embeddings.google_genai requires Python 3.10+")
|
||||
|
||||
# Mock the module creation to avoid import issues
|
||||
mock_module = mock.MagicMock()
|
||||
|
||||
@@ -14,31 +14,12 @@
|
||||
|
||||
"""Unit tests for McpToolset."""
|
||||
|
||||
import sys
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset
|
||||
import pytest
|
||||
|
||||
# Skip all tests in this module if Python version is less than 3.10
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+"
|
||||
)
|
||||
|
||||
# Import dependencies with version checking
|
||||
try:
|
||||
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset
|
||||
except ImportError as e:
|
||||
if sys.version_info < (3, 10):
|
||||
# Create dummy classes to prevent NameError during test collection
|
||||
# Tests will be skipped anyway due to pytestmark
|
||||
class DummyClass:
|
||||
pass
|
||||
|
||||
McpToolset = DummyClass
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_toolset_with_prefix():
|
||||
|
||||
Reference in New Issue
Block a user