15
15
"""Tests for log_utils module."""
16
16
17
17
import json
18
+ import sys
18
19
from unittest .mock import Mock
19
20
from unittest .mock import patch
20
21
21
22
import pytest
22
23
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
40
40
41
41
42
42
class TestBuildMessagePartLog :
43
43
"""Test suite for build_message_part_log function."""
44
44
45
- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
46
45
def test_text_part_short_text (self ):
47
46
"""Test TextPart with short text."""
48
- # Import here to avoid import issues at module level
49
47
from google .adk .a2a .logs .log_utils import build_message_part_log
50
48
51
49
# Create real A2A objects
@@ -56,7 +54,6 @@ def test_text_part_short_text(self):
56
54
57
55
assert result == "TextPart: Hello, world!"
58
56
59
- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
60
57
def test_text_part_long_text (self ):
61
58
"""Test TextPart with long text that gets truncated."""
62
59
from google .adk .a2a .logs .log_utils import build_message_part_log
@@ -70,7 +67,6 @@ def test_text_part_long_text(self):
70
67
expected = f"TextPart: { 'x' * 100 } ..."
71
68
assert result == expected
72
69
73
- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
74
70
def test_data_part_simple_data (self ):
75
71
"""Test DataPart with simple data."""
76
72
from google .adk .a2a .logs .log_utils import build_message_part_log
@@ -84,7 +80,6 @@ def test_data_part_simple_data(self):
84
80
expected = f"DataPart: { json .dumps (expected_data , indent = 2 )} "
85
81
assert result == expected
86
82
87
- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
88
83
def test_data_part_large_values (self ):
89
84
"""Test DataPart with large values that get summarized."""
90
85
from google .adk .a2a .logs .log_utils import build_message_part_log
@@ -278,7 +273,6 @@ def test_error_response_no_data(self):
278
273
assert "Not Found" in result
279
274
assert "Error Data: None" in result
280
275
281
- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
282
276
def test_success_response_with_task (self ):
283
277
"""Test success response logging with Task result."""
284
278
# Use module-level imported types consistently
@@ -309,7 +303,6 @@ def test_success_response_with_task(self):
309
303
or '"state": "working"' in result
310
304
)
311
305
312
- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
313
306
def test_success_response_with_task_and_status_message (self ):
314
307
"""Test success response with Task that has status message."""
315
308
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):
353
346
)
354
347
assert "Message Parts:" in result
355
348
356
- @pytest .mark .skipif (not A2A_AVAILABLE , reason = "A2A types not available" )
357
349
def test_success_response_with_message (self ):
358
350
"""Test success response logging with Message result."""
359
351
from google .adk .a2a .logs .log_utils import build_a2a_response_log
0 commit comments