|
20 | 20 | from unittest.mock import Mock |
21 | 21 | from unittest.mock import patch |
22 | 22 |
|
23 | | -# Try to import a2a library - will fail on Python < 3.10 |
| 23 | +import pytest |
| 24 | + |
| 25 | +# Check if A2A dependencies are available |
| 26 | +A2A_AVAILABLE = True |
24 | 27 | try: |
25 | 28 | from a2a.types import AgentCapabilities |
26 | 29 | from a2a.types import AgentCard |
|
32 | 35 | from google.adk.agents.remote_a2a_agent import A2A_METADATA_PREFIX |
33 | 36 | from google.adk.agents.remote_a2a_agent import AgentCardResolutionError |
34 | 37 | from google.adk.agents.remote_a2a_agent import RemoteA2aAgent |
35 | | - |
36 | | - A2A_AVAILABLE = True |
37 | 38 | except ImportError: |
38 | 39 | A2A_AVAILABLE = False |
| 40 | + |
39 | 41 | # Create dummy classes to prevent NameError during test collection |
40 | | - AgentCapabilities = type("AgentCapabilities", (), {}) |
41 | | - AgentCard = type("AgentCard", (), {}) |
42 | | - AgentSkill = type("AgentSkill", (), {}) |
43 | | - A2AMessage = type("A2AMessage", (), {}) |
44 | | - SendMessageSuccessResponse = type("SendMessageSuccessResponse", (), {}) |
45 | | - A2ATask = type("A2ATask", (), {}) |
| 42 | + class DummyTypes: |
| 43 | + pass |
| 44 | + |
| 45 | + AgentCapabilities = DummyTypes() |
| 46 | + AgentCard = DummyTypes() |
| 47 | + AgentSkill = DummyTypes() |
| 48 | + A2AMessage = DummyTypes() |
| 49 | + SendMessageSuccessResponse = DummyTypes() |
| 50 | + A2ATask = DummyTypes() |
| 51 | + InvocationContext = DummyTypes() |
| 52 | + RemoteA2aAgent = DummyTypes() |
| 53 | + AgentCardResolutionError = Exception |
| 54 | + A2A_METADATA_PREFIX = "" |
| 55 | + |
| 56 | +# Skip all tests in this module if Python < 3.10 or A2A dependencies are not available |
| 57 | +pytestmark = pytest.mark.skipif( |
| 58 | + sys.version_info < (3, 10) or not A2A_AVAILABLE, |
| 59 | + reason="A2A requires Python 3.10+ and A2A dependencies must be available", |
| 60 | +) |
46 | 61 |
|
47 | 62 |
|
48 | 63 | from google.adk.events.event import Event |
49 | 64 | from google.adk.sessions.session import Session |
50 | 65 | import httpx |
51 | | -import pytest |
52 | | - |
53 | | -# Skip all tests in this module if Python < 3.10 or a2a library is not available |
54 | | -pytestmark = pytest.mark.skipif( |
55 | | - sys.version_info < (3, 10) or not A2A_AVAILABLE, |
56 | | - reason=( |
57 | | - "a2a library requires Python 3.10+ and is not available, skipping" |
58 | | - " RemoteA2aAgent tests" |
59 | | - ), |
60 | | -) |
61 | 66 |
|
62 | 67 |
|
63 | 68 | # Helper function to create a proper AgentCard for testing |
|
0 commit comments