10000 chore: skip mcp and a2a tests for python 3.9 · google/adk-python@71bece2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71bece2

Browse files
seanzhougooglecopybara-github
authored andcommitted
chore: skip mcp and a2a tests for python 3.9
PiperOrigin-RevId: 773100777
1 parent 2f716ad commit 71bece2

File tree

4 files changed

+121
-36
lines changed

4 files changed

+121
-36
lines changed

tests/unittests/a2a/converters/test_part_converter.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,43 @@
1313
# limitations under the License.
1414

1515
import json
16+
import sys
1617
from unittest.mock import Mock
1718
from unittest.mock import patch
1819

19-
from a2a import types as a2a_types
20-
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL
21-
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE
22-
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_KEY
23-
from google.adk.a2a.converters.part_converter import convert_a2a_part_to_genai_part
24-
from google.adk.a2a.converters.part_converter import convert_genai_part_to_a2a_part
25-
from google.genai import types as genai_types
2620
import pytest
2721

22+
# Skip all tests in this module if Python version is less than 3.10
23+
pytestmark = pytest.mark.skipif(
24+
sys.version_info < (3, 10), reason="A2A tool requires Python 3.10+"
25+
)
26+
27+
# Import dependencies with version checking
28+
try:
29+
from a2a import types as a2a_types
30+
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL
31+
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE
32+
from google.adk.a2a.converters.part_converter import A2A_DATA_PART_METADATA_TYPE_KEY
33+
from google.adk.a2a.converters.part_converter import convert_a2a_part_to_genai_part
34+
from google.adk.a2a.converters.part_converter import convert_genai_part_to_a2a_part
35+
from google.genai import types as genai_types
36+
except ImportError as e:
37+
if sys.version_info < (3, 10):
38+
# Create dummy classes to prevent NameError during test collection
39+
# Tests will be skipped anyway due to pytestmark
40+
class DummyTypes:
41+
pass
42+
43+
a2a_types = DummyTypes()
44+
genai_types = DummyTypes()
45+
A2A_DATA_PART_METADATA_TYPE_FUNCTION_CALL = "function_call"
46+
A2A_DATA_PART_METADATA_TYPE_FUNCTION_RESPONSE = "function_response"
47+
A2A_DATA_PART_METADATA_TYPE_KEY = "type"
48+
convert_a2a_part_to_genai_part = lambda x: None
49+
convert_genai_part_to_a2a_part = lambda x: None
50+
else:
51+
raise e
52+
2853

2954
class TestConvertA2aPartToGenaiPart:
3055
"""Test cases for convert_a2a_part_to_genai_part function."""

tests/unittests/tools/mcp_tool/test_mcp_session_manager.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,35 @@
2020
from unittest.mock import Mock
2121
from unittest.mock import patch
2222

23-
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
24-
from google.adk.tools.mcp_tool.mcp_session_manager import retry_on_closed_resource
25-
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams
26-
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
27-
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
2823
import pytest
2924

25+
# Skip all tests in this module if Python version is less than 3.10
26+
pytestmark = pytest.mark.skipif(
27+
sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+"
28+
)
29+
30+
# Import dependencies with version checking
31+
try:
32+
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
33+
from google.adk.tools.mcp_tool.mcp_session_manager import retry_on_closed_resource
34+
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams
35+
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
36+
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
37+
except ImportError as e:
38+
if sys.version_info < (3, 10):
39+
# Create dummy classes to prevent NameError during test collection
40+
# Tests will be skipped anyway due to pytestmark
41+
class DummyClass:
42+
pass
43+
44+
MCPSessionManager = DummyClass
45+
retry_on_closed_resource = lambda x: x
46+
SseConnectionParams = DummyClass
47+
StdioConnectionParams = DummyClass
48+
StreamableHTTPConnectionParams = DummyClass
49+
else:
50+
raise e
51+
3052
# Import real MCP classes
3153
try:
3254
from mcp import StdioServerParameters

tests/unittests/tools/mcp_tool/test_mcp_tool.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import json
15+
import sys
16+
from typing import Any
17+
from typing import Dict
1618
from unittest.mock import AsyncMock
1719
from unittest.mock import Mock
1820
from unittest.mock import patch
@@ -23,14 +25,33 @@
2325
from google.adk.auth.auth_credential import HttpCredentials
2426
from google.adk.auth.auth_credential import OAuth2Auth
2527
from google.adk.auth.auth_credential import ServiceAccount
26-
from google.adk.auth.auth_schemes import AuthScheme
27-
from google.adk.auth.auth_schemes import AuthSchemeType
28-
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
29-
from google.adk.tools.mcp_tool.mcp_tool import MCPTool
30-
from < F438 span class=pl-s1>google.adk.tools.tool_context import ToolContext
31-
from google.genai.types import FunctionDeclaration
3228
import pytest
3329

30+
# Skip all tests in this module if Python version is less than 3.10
31+
pytestmark = pytest.mark.skipif(
32+
sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+"
33+
)
34+
35+
# Import dependencies with version checking
36+
try:
37+
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
38+
from google.adk.tools.mcp_tool.mcp_tool import MCPTool
39+
from google.adk.tools.tool_context import ToolContext
40+
from google.genai.types import FunctionDeclaration
41+
except ImportError as e:
42+
if sys.version_info < (3, 10):
43+
# Create dummy classes to prevent NameError during test collection
44+
# Tests will be skipped anyway due to pytestmark
45+
class DummyClass:
46+
pass
47+
48+
MCPSessionManager = DummyClass
49+
MCPTool = DummyClass
50+
ToolContext = DummyClass
51+
FunctionDeclaration = DummyClass
52+
else:
53+
raise e
54+
3455

3556
# Mock MCP Tool from mcp.types
3657
class MockMCPTool:

tests/unittests/tools/mcp_tool/test_mcp_toolset.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,49 @@
1414

1515
from io import StringIO
1616
import sys
17+
import unittest
1718
from unittest.mock import AsyncMock
1819
from unittest.mock import Mock
1920
from unittest.mock import patch
2021

21-
from google.adk.agents.readonly_context import ReadonlyContext
2222
from google.adk.auth.auth_credential import AuthCredential
23-
from google.adk.auth.auth_schemes import AuthScheme
24-
from google.adk.auth.auth_schemes import AuthSchemeType
25-
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
26-
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams
27-
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
28-
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
29-
from google.adk.tools.mcp_tool.mcp_tool import MCPTool
30-
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
3123
import pytest
3224

33-
# Import the real MCP classes for proper instantiation
25+
# Skip all tests in this module if Python version is less than 3.10
26+
pytestmark = pytest.mark.skipif(
27+
sys.version_info < (3, 10), reason="MCP tool requires Python 3.10+"
28+
)
29+
30+
# Import dependencies with version checking
3431
try:
32+
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
33+
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams
34+
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
35+
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
36+
from google.adk.tools.mcp_tool.mcp_tool import MCPTool
37+
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset
3538
from mcp import StdioServerParameters
36-
except ImportError:
37-
# Create a mock if MCP is not available
38-
class StdioServerParameters:
39-
40-
def __init__(self, command="test_command", args=None):
41-
self.command = command
42-
self.args = args or []
39+
except ImportError as e:
40+
if sys.version_info < (3, 10):
41+
# Create dummy classes to prevent NameError during test collection
42+
# Tests will be skipped anyway due to pytestmark
43+
class DummyClass:
44+
pass
45+
46+
class StdioServerParameters:
47+
48+
def __init__(self, command="test_command", args=None):
49+
self.command = command
50+
self.args = args or []
51+
52+
MCPSessionManager = DummyClass
53+
SseConnectionParams = DummyClass
54+
StdioConnectionParams = DummyClass
55+
StreamableHTTPConnectionParams = DummyClass
56+
MCPTool = DummyClass
57+
MCPToolset = DummyClass
58+
else:
59+
raise e
4360

4461

4562
class MockMCPTool:

0 commit comments

Comments
 (0)
0