Skip to content

Commit 000b8c0

Browse files
committed
Formatting
1 parent 1e06d18 commit 000b8c0

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

tests/utils/test_message.py

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from unittest.mock import patch
21
import uuid
32

3+
from unittest.mock import patch
4+
45
from a2a.types import (
56
Message,
67
Part,
78
Role,
89
TextPart,
910
)
10-
from a2a.utils import new_agent_text_message, get_text_parts, get_message_text
11+
from a2a.utils import get_message_text, get_text_parts, new_agent_text_message
1112

1213

1314
class TestNewAgentTextMessage:
@@ -16,7 +17,10 @@ def test_new_agent_text_message_basic(self):
1617
text = "Hello, I'm an agent"
1718

1819
# Exercise - with a fixed uuid for testing
19-
with patch('uuid.uuid4', return_value=uuid.UUID('12345678-1234-5678-1234-567812345678')):
20+
with patch(
21+
'uuid.uuid4',
22+
return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'),
23+
):
2024
message = new_agent_text_message(text)
2125

2226
# Verify
@@ -29,11 +33,14 @@ def test_new_agent_text_message_basic(self):
2933

3034
def test_new_agent_text_message_with_context_id(self):
3135
# Setup
32-
text = "Message with context"
33-
context_id = "test-context-id"
36+
text = 'Message with context'
37+
context_id = 'test-context-id'
3438

3539
# Exercise
36-
with patch('uuid.uuid4', return_value=uuid.UUID('12345678-1234-5678-1234-567812345678')):
40+
with patch(
41+
'uuid.uuid4',
42+
return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'),
43+
):
3744
message = new_agent_text_message(text, context_id=context_id)
3845

3946
# Verify
@@ -45,11 +52,14 @@ def test_new_agent_text_message_with_context_id(self):
4552

4653
def test_new_agent_text_message_with_task_id(self):
4754
# Setup
48-
text = "Message with task id"
49-
task_id = "test-task-id"
55+
text = 'Message with task id'
56+
task_id = 'test-task-id'
5057

5158
# Exercise
52-
with patch('uuid.uuid4', return_value=uuid.UUID('12345678-1234-5678-1234-567812345678')):
59+
with patch(
60+
'uuid.uuid4',
61+
return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'),
62+
):
5363
message = new_agent_text_message(text, task_id=task_id)
5464

5565
# Verify
@@ -61,13 +71,18 @@ def test_new_agent_text_message_with_task_id(self):
6171

6272
def test_new_agent_text_message_with_both_ids(self):
6373
# Setup
64-
text = "Message with both ids"
65-
context_id = "test-context-id"
66-
task_id = "test-task-id"
74+
text = 'Message with both ids'
75+
context_id = 'test-context-id'
76+
task_id = 'test-task-id'
6777

6878
# Exercise
69-
with patch('uuid.uuid4', return_value=uuid.UUID('12345678-1234-5678-1234-567812345678')):
70-
message = new_agent_text_message(text, context_id=context_id, task_id=task_id)
79+
with patch(
80+
'uuid.uuid4',
81+
return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'),
82+
):
83+
message = new_agent_text_message(
84+
text, context_id=context_id, task_id=task_id
85+
)
7186

7287
# Verify
7388
assert message.role == Role.agent
@@ -78,42 +93,45 @@ def test_new_agent_text_message_with_both_ids(self):
7893

7994
def test_new_agent_text_message_empty_text(self):
8095
# Setup
81-
text = ""
96+
text = ''
8297

8398
# Exercise
84-
with patch('uuid.uuid4', return_value=uuid.UUID('12345678-1234-5678-1234-567812345678')):
99+
with patch(
100+
'uuid.uuid4',
101+
return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'),
102+
):
85103
message = new_agent_text_message(text)
86104

87105
# Verify
88106
assert message.role == Role.agent
89-
assert message.parts[0].root.text == ""
107+
assert message.parts[0].root.text == ''
90108
assert message.messageId == '12345678-1234-5678-1234-567812345678'
91109

92110

93111
class TestGetTextParts:
94112
def test_get_text_parts_single_text_part(self):
95113
# Setup
96-
parts = [Part(root=TextPart(text="Hello world"))]
114+
parts = [Part(root=TextPart(text='Hello world'))]
97115

98116
# Exercise
99117
result = get_text_parts(parts)
100118

101119
# Verify
102-
assert result == ["Hello world"]
120+
assert result == ['Hello world']
103121

104122
def test_get_text_parts_multiple_text_parts(self):
105123
# Setup
106124
parts = [
107-
Part(root=TextPart(text="First part")),
108-
Part(root=TextPart(text="Second part")),
109-
Part(root=TextPart(text="Third part")),
125+
Part(root=TextPart(text='First part')),
126+
Part(root=TextPart(text='Second part')),
127+
Part(root=TextPart(text='Third part')),
110128
]
111129

112130
# Exercise
113131
result = get_text_parts(parts)
114132

115133
# Verify
116-
assert result == ["First part", "Second part", "Third part"]
134+
assert result == ['First part', 'Second part', 'Third part']
117135

118136
def test_get_text_parts_empty_list(self):
119137
# Setup
@@ -131,62 +149,62 @@ def test_get_message_text_single_part(self):
131149
# Setup
132150
message = Message(
133151
role=Role.agent,
134-
parts=[Part(root=TextPart(text="Hello world"))],
135-
messageId="test-message-id",
152+
parts=[Part(root=TextPart(text='Hello world'))],
153+
messageId='test-message-id',
136154
)
137155

138156
# Exercise
139157
result = get_message_text(message)
140158

141159
# Verify
142-
assert result == "Hello world"
160+
assert result == 'Hello world'
143161

144162
def test_get_message_text_multiple_parts(self):
145163
# Setup
146164
message = Message(
147165
role=Role.agent,
148166
parts=[
149-
Part(root=TextPart(text="First line")),
150-
Part(root=TextPart(text="Second line")),
151-
Part(root=TextPart(text="Third line")),
167+
Part(root=TextPart(text='First line')),
168+
Part(root=TextPart(text='Second line')),
169+
Part(root=TextPart(text='Third line')),
152170
],
153-
messageId="test-message-id",
171+
messageId='test-message-id',
154172
)
155173

156174
# Exercise
157175
result = get_message_text(message)
158176

159177
# Verify - default delimiter is newline
160-
assert result == "First line\nSecond line\nThird line"
178+
assert result == 'First line\nSecond line\nThird line'
161179

162180
def test_get_message_text_custom_delimiter(self):
163181
# Setup
164182
message = Message(
165183
role=Role.agent,
166184
parts=[
167-
Part(root=TextPart(text="First part")),
168-
Part(root=TextPart(text="Second part")),
169-
Part(root=TextPart(text="Third part")),
185+
Part(root=TextPart(text='First part')),
186+
Part(root=TextPart(text='Second part')),
187+
Part(root=TextPart(text='Third part')),
170188
],
171-
messageId="test-message-id",
189+
messageId='test-message-id',
172190
)
173191

174192
# Exercise
175-
result = get_message_text(message, delimiter=" | ")
193+
result = get_message_text(message, delimiter=' | ')
176194

177195
# Verify
178-
assert result == "First part | Second part | Third part"
196+
assert result == 'First part | Second part | Third part'
179197

180198
def test_get_message_text_empty_parts(self):
181199
# Setup
182200
message = Message(
183201
role=Role.agent,
184202
parts=[],
185-
messageId="test-message-id",
203+
messageId='test-message-id',
186204
)
187205

188206
# Exercise
189207
result = get_message_text(message)
190208

191209
# Verify
192-
assert result == ""
210+
assert result == ''

0 commit comments

Comments
 (0)