|
3 | 3 | import pytest |
4 | 4 |
|
5 | 5 | from a2a.client import A2AClientError, A2AClientHTTPError, A2AClientJSONError |
| 6 | +from a2a.client.errors import ( |
| 7 | + A2AClientInvalidArgsError, |
| 8 | + A2AClientInvalidStateError, |
| 9 | + A2AClientJSONRPCError, |
| 10 | + A2AClientTimeoutError, |
| 11 | +) |
| 12 | +from a2a.types import JSONRPCError, JSONRPCErrorResponse |
6 | 13 |
|
7 | 14 |
|
8 | 15 | class TestA2AClientError: |
@@ -35,6 +42,14 @@ def test_message_formatting(self) -> None: |
35 | 42 | error = A2AClientHTTPError(500, 'Internal Server Error') |
36 | 43 | assert str(error) == 'HTTP Error 500: Internal Server Error' |
37 | 44 |
|
| 45 | + def test_repr(self) -> None: |
| 46 | + """Test that __repr__ shows structured attributes.""" |
| 47 | + error = A2AClientHTTPError(404, 'Not Found') |
| 48 | + assert ( |
| 49 | + repr(error) |
| 50 | + == "A2AClientHTTPError(status_code=404, message='Not Found')" |
| 51 | + ) |
| 52 | + |
38 | 53 | def test_inheritance(self) -> None: |
39 | 54 | """Test that A2AClientHTTPError inherits from A2AClientError.""" |
40 | 55 | error = A2AClientHTTPError(400, 'Bad Request') |
@@ -81,6 +96,13 @@ def test_message_formatting(self) -> None: |
81 | 96 | error = A2AClientJSONError('Missing required field') |
82 | 97 | assert str(error) == 'JSON Error: Missing required field' |
83 | 98 |
|
| 99 | + def test_repr(self) -> None: |
| 100 | + """Test that __repr__ shows structured attributes.""" |
| 101 | + error = A2AClientJSONError('Invalid JSON format') |
| 102 | + assert ( |
| 103 | + repr(error) == "A2AClientJSONError(message='Invalid JSON format')" |
| 104 | + ) |
| 105 | + |
84 | 106 | def test_inheritance(self) -> None: |
85 | 107 | """Test that A2AClientJSONError inherits from A2AClientError.""" |
86 | 108 | error = A2AClientJSONError('Parsing error') |
@@ -108,6 +130,57 @@ def test_with_various_messages(self) -> None: |
108 | 130 | assert str(error) == f'JSON Error: {message}' |
109 | 131 |
|
110 | 132 |
|
| 133 | +class TestA2AClientTimeoutErrorRepr: |
| 134 | + """Test __repr__ for A2AClientTimeoutError.""" |
| 135 | + |
| 136 | + def test_repr(self) -> None: |
| 137 | + """Test that __repr__ shows structured attributes.""" |
| 138 | + error = A2AClientTimeoutError('Request timed out') |
| 139 | + assert ( |
| 140 | + repr(error) == "A2AClientTimeoutError(message='Request timed out')" |
| 141 | + ) |
| 142 | + |
| 143 | + |
| 144 | +class TestA2AClientInvalidArgsErrorRepr: |
| 145 | + """Test __repr__ for A2AClientInvalidArgsError.""" |
| 146 | + |
| 147 | + def test_repr(self) -> None: |
| 148 | + """Test that __repr__ shows structured attributes.""" |
| 149 | + error = A2AClientInvalidArgsError('Missing required param') |
| 150 | + assert ( |
| 151 | + repr(error) |
| 152 | + == "A2AClientInvalidArgsError(message='Missing required param')" |
| 153 | + ) |
| 154 | + |
| 155 | + |
| 156 | +class TestA2AClientInvalidStateErrorRepr: |
| 157 | + """Test __repr__ for A2AClientInvalidStateError.""" |
| 158 | + |
| 159 | + def test_repr(self) -> None: |
| 160 | + """Test that __repr__ shows structured attributes.""" |
| 161 | + error = A2AClientInvalidStateError('Client not initialized') |
| 162 | + assert ( |
| 163 | + repr(error) |
| 164 | + == "A2AClientInvalidStateError(message='Client not initialized')" |
| 165 | + ) |
| 166 | + |
| 167 | + |
| 168 | +class TestA2AClientJSONRPCErrorRepr: |
| 169 | + """Test __repr__ for A2AClientJSONRPCError.""" |
| 170 | + |
| 171 | + def test_repr(self) -> None: |
| 172 | + """Test that __repr__ shows the JSON-RPC error object.""" |
| 173 | + response = JSONRPCErrorResponse( |
| 174 | + id='test-1', |
| 175 | + error=JSONRPCError(code=-32601, message='Method not found'), |
| 176 | + ) |
| 177 | + error = A2AClientJSONRPCError(response) |
| 178 | + assert ( |
| 179 | + repr(error) |
| 180 | + == "A2AClientJSONRPCError(JSONRPCError(code=-32601, data=None, message='Method not found'))" |
| 181 | + ) |
| 182 | + |
| 183 | + |
111 | 184 | class TestExceptionHierarchy: |
112 | 185 | """Test the exception hierarchy and relationships.""" |
113 | 186 |
|
|
0 commit comments