1515"""Tests for log_utils module."""
1616
1717import json
18+ import sys
1819from unittest .mock import Mock
1920from unittest .mock import patch
2021
2122import pytest
2223
23- # Import the actual A2A types that we need to mock
24- try :
25- from a2a .types import DataPart as A2ADataPart
26- from a2a .types import Message as A2AMessage
27- from a2a .types import MessageSendConfiguration
28- from a2a .types import MessageSendParams
29- from a2a .types import Part as A2APart
30- from a2a .types import Role
31- from a2a .types import SendMessageRequest
32- from a2a .types import Task as A2ATask
33- from a2a .types import TaskState
34- from a2a .types import TaskStatus
35- from a2a .types import TextPart as A2ATextPart
36-
37- A2A_AVAILABLE = True
38- except ImportError :
39- A2A_AVAILABLE = False
24+ # Skip entire module if Python < 3.10
25+ if sys .version_info < (3 , 10 ):
26+ pytest .skip ("A2A requires Python 3.10+" , allow_module_level = True )
27+
28+ # Normal imports after the skip
29+ from a2a .types import DataPart as A2ADataPart
30+ from a2a .types import Message as A2AMessage
31+ from a2a .types import MessageSendConfiguration
32+ from a2a .types import MessageSendParams
33+ from a2a .types import Part as A2APart
34+ from a2a .types import Role
35+ from a2a .types import SendMessageRequest
36+ from a2a .types import Task as A2ATask
37+ from a2a .types import TaskState
38+ from a2a .types import TaskStatus
39+ from a2a .types import TextPart as A2ATextPart
4040
4141
4242class TestBuildMessagePartLog :
4343 """Test suite for build_message_part_log function."""
4444
45- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
4645 def test_text_part_short_text (self ):
4746 """Test TextPart with short text."""
48- # Import here to avoid import issues at module level
4947 from google .adk .a2a .logs .log_utils import build_message_part_log
5048
5149 # Create real A2A objects
@@ -56,7 +54,6 @@ def test_text_part_short_text(self):
5654
5755 assert result == "TextPart: Hello, world!"
5856
59- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
6057 def test_text_part_long_text (self ):
6158 """Test TextPart with long text that gets truncated."""
6259 from google .adk .a2a .logs .log_utils import build_message_part_log
@@ -70,7 +67,6 @@ def test_text_part_long_text(self):
7067 expected = f"TextPart: { 'x' * 100 } ..."
7168 assert result == expected
7269
73- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
7470 def test_data_part_simple_data (self ):
7571 """Test DataPart with simple data."""
7672 from google .adk .a2a .logs .log_utils import build_message_part_log
@@ -84,7 +80,6 @@ def test_data_part_simple_data(self):
8480 expected = f"DataPart: { json .dumps (expected_data , indent = 2 )} "
8581 assert result == expected
8682
87- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
8883 def test_data_part_large_values (self ):
8984 """Test DataPart with large values that get summarized."""
9085 from google .adk .a2a .logs .log_utils import build_message_part_log
@@ -278,7 +273,6 @@ def test_error_response_no_data(self):
278273 assert "Not Found" in result
279274 assert "Error Data: None" in result
280275
281- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
282276 def test_success_response_with_task (self ):
283277 """Test success response logging with Task result."""
284278 # Use module-level imported types consistently
@@ -309,7 +303,6 @@ def test_success_response_with_task(self):
309303 or '"state": "working"' in result
310304 )
311305
312- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
313306 def test_success_response_with_task_and_status_message (self ):
314307 """Test success response with Task that has status message."""
315308 from google .adk .a2a .logs .log_utils import build_a2a_response_log
@@ -353,7 +346,6 @@ def test_success_response_with_task_and_status_message(self):
353346 )
354347 assert "Message Parts:" in result
355348
356- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
357349 def test_success_response_with_message (self ):
358350 """Test success response logging with Message result."""
359351 from google .adk .a2a .logs .log_utils import build_a2a_response_log
0 commit comments