Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions tests/unittests/a2a/executor/test_task_result_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,19 @@

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):
# Create dummy classes to prevent NameError during test collection
# Tests will be skipped anyway due to pytestmark
class DummyTypes:
pass

TaskState = DummyTypes()
TaskStatus = DummyTypes()
TaskStatusUpdateEvent = DummyTypes()
TaskResultAggregator = DummyTypes()
else:
raise e
# Skip entire module if Python < 3.10
if sys.version_info < (3, 10):
pytest.skip("A2A requires Python 3.10+", allow_module_level=True)

# Normal imports after the skip
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


def create_test_message(text: str) -> Message:
Expand Down
42 changes: 17 additions & 25 deletions tests/unittests/a2a/logs/test_log_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,35 @@
"""Tests for log_utils module."""

import json
import sys
from unittest.mock import Mock
from unittest.mock import patch

import pytest

# Import the actual A2A types that we need to mock
try:
from a2a.types import DataPart as A2ADataPart
from a2a.types import Message as A2AMessage
from a2a.types import MessageSendConfiguration
from a2a.types import MessageSendParams
from a2a.types import Part as A2APart
from a2a.types import Role
from a2a.types import SendMessageRequest
from a2a.types import Task as A2ATask
from a2a.types import TaskState
from a2a.types import TaskStatus
from a2a.types import TextPart as A2ATextPart

A2A_AVAILABLE = True
except ImportError:
A2A_AVAILABLE = False
# Skip entire module if Python < 3.10
if sys.version_info < (3, 10):
pytest.skip("A2A requires Python 3.10+", allow_module_level=True)

# Normal imports after the skip
from a2a.types import DataPart as A2ADataPart
from a2a.types import Message as A2AMessage
from a2a.types import MessageSendConfiguration
from a2a.types import MessageSendParams
from a2a.types import Part as A2APart
from a2a.types import Role
from a2a.types import SendMessageRequest
from a2a.types import Task as A2ATask
from a2a.types import TaskState
from a2a.types import TaskStatus
from a2a.types import TextPart as A2ATextPart


class TestBuildMessagePartLog:
"""Test suite for build_message_part_log function."""

@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
def test_text_part_short_text(self):
"""Test TextPart with short text."""
# Import here to avoid import issues at module level
from google.adk.a2a.logs.log_utils import build_message_part_log

# Create real A2A objects
Expand All @@ -56,7 +54,6 @@ def test_text_part_short_text(self):

assert result == "TextPart: Hello, world!"

@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
def test_text_part_long_text(self):
"""Test TextPart with long text that gets truncated."""
from google.adk.a2a.logs.log_utils import build_message_part_log
Expand All @@ -70,7 +67,6 @@ def test_text_part_long_text(self):
expected = f"TextPart: {'x' * 100}..."
assert result == expected

@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
def test_data_part_simple_data(self):
"""Test DataPart with simple data."""
from google.adk.a2a.logs.log_utils import build_message_part_log
Expand All @@ -84,7 +80,6 @@ def test_data_part_simple_data(self):
expected = f"DataPart: {json.dumps(expected_data, indent=2)}"
assert result == expected

@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
def test_data_part_large_values(self):
"""Test DataPart with large values that get summarized."""
from google.adk.a2a.logs.log_utils import build_message_part_log
Expand Down Expand Up @@ -278,7 +273,6 @@ def test_error_response_no_data(self):
assert "Not Found" in result
assert "Error Data: None" in result

@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
def test_success_response_with_task(self):
"""Test success response logging with Task result."""
# Use module-level imported types consistently
Expand Down Expand Up @@ -309,7 +303,6 @@ def test_success_response_with_task(self):
or '"state": "working"' in result
)

@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
def test_success_response_with_task_and_status_message(self):
"""Test success response with Task that has status message."""
from google.adk.a2a.logs.log_utils import build_a2a_response_log
Expand Down Expand Up @@ -353,7 +346,6 @@ def test_success_response_with_task_and_status_message(self):
)
assert "Message Parts:" in result

@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
def test_success_response_with_message(self):
"""Test success response logging with Message result."""
from google.adk.a2a.logs.log_utils import build_a2a_response_log
Expand Down