Skip to content

Commit 28a3950

Browse files
committed
Formatting
1 parent ab9299f commit 28a3950

File tree

1 file changed

+64
-56
lines changed

1 file changed

+64
-56
lines changed

tests/client/test_errors.py

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import pytest
22

3-
from a2a.client import A2AClientHTTPError, A2AClientError, A2AClientJSONError
3+
from a2a.client import A2AClientError, A2AClientHTTPError, A2AClientJSONError
4+
45

56
class TestA2AClientError:
67
"""Test cases for the base A2AClientError class."""
78

89
def test_instantiation(self):
910
"""Test that A2AClientError can be instantiated."""
10-
error = A2AClientError("Test error message")
11+
error = A2AClientError('Test error message')
1112
assert isinstance(error, Exception)
12-
assert str(error) == "Test error message"
13+
assert str(error) == 'Test error message'
1314

1415
def test_inheritance(self):
1516
"""Test that A2AClientError inherits from Exception."""
@@ -22,87 +23,87 @@ class TestA2AClientHTTPError:
2223

2324
def test_instantiation(self):
2425
"""Test that A2AClientHTTPError can be instantiated with status_code and message."""
25-
error = A2AClientHTTPError(404, "Not Found")
26+
error = A2AClientHTTPError(404, 'Not Found')
2627
assert isinstance(error, A2AClientError)
2728
assert error.status_code == 404
28-
assert error.message == "Not Found"
29+
assert error.message == 'Not Found'
2930

3031
def test_message_formatting(self):
3132
"""Test that the error message is formatted correctly."""
32-
error = A2AClientHTTPError(500, "Internal Server Error")
33-
assert str(error) == "HTTP Error 500: Internal Server Error"
33+
error = A2AClientHTTPError(500, 'Internal Server Error')
34+
assert str(error) == 'HTTP Error 500: Internal Server Error'
3435

3536
def test_inheritance(self):
3637
"""Test that A2AClientHTTPError inherits from A2AClientError."""
37-
error = A2AClientHTTPError(400, "Bad Request")
38+
error = A2AClientHTTPError(400, 'Bad Request')
3839
assert isinstance(error, A2AClientError)
3940

4041
def test_with_empty_message(self):
4142
"""Test behavior with an empty message."""
42-
error = A2AClientHTTPError(403, "")
43+
error = A2AClientHTTPError(403, '')
4344
assert error.status_code == 403
44-
assert error.message == ""
45-
assert str(error) == "HTTP Error 403: "
45+
assert error.message == ''
46+
assert str(error) == 'HTTP Error 403: '
4647

4748
def test_with_various_status_codes(self):
4849
"""Test with different HTTP status codes."""
4950
test_cases = [
50-
(200, "OK"),
51-
(201, "Created"),
52-
(400, "Bad Request"),
53-
(401, "Unauthorized"),
54-
(403, "Forbidden"),
55-
(404, "Not Found"),
56-
(500, "Internal Server Error"),
57-
(503, "Service Unavailable")
51+
(200, 'OK'),
52+
(201, 'Created'),
53+
(400, 'Bad Request'),
54+
(401, 'Unauthorized'),
55+
(403, 'Forbidden'),
56+
(404, 'Not Found'),
57+
(500, 'Internal Server Error'),
58+
(503, 'Service Unavailable'),
5859
]
5960

6061
for status_code, message in test_cases:
6162
error = A2AClientHTTPError(status_code, message)
6263
assert error.status_code == status_code
6364
assert error.message == message
64-
assert str(error) == f"HTTP Error {status_code}: {message}"
65+
assert str(error) == f'HTTP Error {status_code}: {message}'
6566

6667

6768
class TestA2AClientJSONError:
6869
"""Test cases for A2AClientJSONError class."""
6970

7071
def test_instantiation(self):
7172
"""Test that A2AClientJSONError can be instantiated with a message."""
72-
error = A2AClientJSONError("Invalid JSON format")
73+
error = A2AClientJSONError('Invalid JSON format')
7374
assert isinstance(error, A2AClientError)
74-
assert error.message == "Invalid JSON format"
75+
assert error.message == 'Invalid JSON format'
7576

7677
def test_message_formatting(self):
7778
"""Test that the error message is formatted correctly."""
78-
error = A2AClientJSONError("Missing required field")
79-
assert str(error) == "JSON Error: Missing required field"
79+
error = A2AClientJSONError('Missing required field')
80+
assert str(error) == 'JSON Error: Missing required field'
8081

8182
def test_inheritance(self):
8283
"""Test that A2AClientJSONError inherits from A2AClientError."""
83-
error = A2AClientJSONError("Parsing error")
84+
error = A2AClientJSONError('Parsing error')
8485
assert isinstance(error, A2AClientError)
8586

8687
def test_with_empty_message(self):
8788
"""Test behavior with an empty message."""
88-
error = A2AClientJSONError("")
89-
assert error.message == ""
90-
assert str(error) == "JSON Error: "
89+
error = A2AClientJSONError('')
90+
assert error.message == ''
91+
assert str(error) == 'JSON Error: '
9192

9293
def test_with_various_messages(self):
9394
"""Test with different error messages."""
9495
test_messages = [
95-
"Malformed JSON",
96-
"Missing required fields",
97-
"Invalid data type",
98-
"Unexpected JSON structure",
99-
"Empty JSON object"
96+
'Malformed JSON',
97+
'Missing required fields',
98+
'Invalid data type',
99+
'Unexpected JSON structure',
100+
'Empty JSON object',
100101
]
101102

102103
for message in test_messages:
103104
error = A2AClientJSONError(message)
104105
assert error.message == message
105-
assert str(error) == f"JSON Error: {message}"
106+
assert str(error) == f'JSON Error: {message}'
106107

107108

108109
class TestExceptionHierarchy:
@@ -117,16 +118,16 @@ def test_exception_hierarchy(self):
117118
def test_catch_specific_exception(self):
118119
"""Test that specific exceptions can be caught."""
119120
try:
120-
raise A2AClientHTTPError(404, "Not Found")
121+
raise A2AClientHTTPError(404, 'Not Found')
121122
except A2AClientHTTPError as e:
122123
assert e.status_code == 404
123-
assert e.message == "Not Found"
124+
assert e.message == 'Not Found'
124125

125126
def test_catch_base_exception(self):
126127
"""Test that derived exceptions can be caught as base exception."""
127128
exceptions = [
128-
A2AClientHTTPError(404, "Not Found"),
129-
A2AClientJSONError("Invalid JSON")
129+
A2AClientHTTPError(404, 'Not Found'),
130+
A2AClientJSONError('Invalid JSON'),
130131
]
131132

132133
for raised_error in exceptions:
@@ -142,37 +143,41 @@ class TestExceptionRaising:
142143
def test_raising_http_error(self):
143144
"""Test raising an HTTP error and checking its properties."""
144145
with pytest.raises(A2AClientHTTPError) as excinfo:
145-
raise A2AClientHTTPError(429, "Too Many Requests")
146+
raise A2AClientHTTPError(429, 'Too Many Requests')
146147

147148
error = excinfo.value
148149
assert error.status_code == 429
149-
assert error.message == "Too Many Requests"
150-
assert str(error) == "HTTP Error 429: Too Many Requests"
150+
assert error.message == 'Too Many Requests'
151+
assert str(error) == 'HTTP Error 429: Too Many Requests'
151152

152153
def test_raising_json_error(self):
153154
"""Test raising a JSON error and checking its properties."""
154155
with pytest.raises(A2AClientJSONError) as excinfo:
155-
raise A2AClientJSONError("Invalid format")
156+
raise A2AClientJSONError('Invalid format')
156157

157158
error = excinfo.value
158-
assert error.message == "Invalid format"
159-
assert str(error) == "JSON Error: Invalid format"
159+
assert error.message == 'Invalid format'
160+
assert str(error) == 'JSON Error: Invalid format'
160161

161162
def test_raising_base_error(self):
162163
"""Test raising the base error."""
163164
with pytest.raises(A2AClientError) as excinfo:
164-
raise A2AClientError("Generic client error")
165+
raise A2AClientError('Generic client error')
165166

166-
assert str(excinfo.value) == "Generic client error"
167+
assert str(excinfo.value) == 'Generic client error'
167168

168169

169170
# Additional parametrized tests for more comprehensive coverage
170171

171-
@pytest.mark.parametrize("status_code,message,expected", [
172-
(400, "Bad Request", "HTTP Error 400: Bad Request"),
173-
(404, "Not Found", "HTTP Error 404: Not Found"),
174-
(500, "Server Error", "HTTP Error 500: Server Error"),
175-
])
172+
173+
@pytest.mark.parametrize(
174+
'status_code,message,expected',
175+
[
176+
(400, 'Bad Request', 'HTTP Error 400: Bad Request'),
177+
(404, 'Not Found', 'HTTP Error 404: Not Found'),
178+
(500, 'Server Error', 'HTTP Error 500: Server Error'),
179+
],
180+
)
176181
def test_http_error_parametrized(status_code, message, expected):
177182
"""Parametrized test for HTTP errors with different status codes."""
178183
error = A2AClientHTTPError(status_code, message)
@@ -181,11 +186,14 @@ def test_http_error_parametrized(status_code, message, expected):
181186
assert str(error) == expected
182187

183188

184-
@pytest.mark.parametrize("message,expected", [
185-
("Missing field", "JSON Error: Missing field"),
186-
("Invalid type", "JSON Error: Invalid type"),
187-
("Parsing failed", "JSON Error: Parsing failed"),
188-
])
189+
@pytest.mark.parametrize(
190+
'message,expected',
191+
[
192+
('Missing field', 'JSON Error: Missing field'),
193+
('Invalid type', 'JSON Error: Invalid type'),
194+
('Parsing failed', 'JSON Error: Parsing failed'),
195+
],
196+
)
189197
def test_json_error_parametrized(message, expected):
190198
"""Parametrized test for JSON errors with different messages."""
191199
error = A2AClientJSONError(message)

0 commit comments

Comments
 (0)