Skip to content

Commit fd132ae

Browse files
committed
Add Tests
1 parent 03e6b3b commit fd132ae

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

tests/utils/test_message.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
from a2a.types import (
66
DataPart,
7+
FilePart,
8+
FileWithBytes,
9+
FileWithUri,
710
Message,
811
Part,
912
Role,
1013
TextPart,
1114
)
1215
from a2a.utils.message import (
16+
get_data_parts,
17+
get_file_parts,
1318
get_message_text,
1419
get_text_parts,
1520
new_agent_parts_message,
@@ -178,6 +183,134 @@ def test_get_text_parts_empty_list(self):
178183
assert result == []
179184

180185

186+
class TestGetDataParts:
187+
def test_get_data_parts_single_data_part(self):
188+
# Setup
189+
parts = [Part(root=DataPart(data={'key': 'value'}))]
190+
191+
# Exercise
192+
result = get_data_parts(parts)
193+
194+
# Verify
195+
assert result == [{'key': 'value'}]
196+
197+
def test_get_data_parts_multiple_data_parts(self):
198+
# Setup
199+
parts = [
200+
Part(root=DataPart(data={'key1': 'value1'})),
201+
Part(root=DataPart(data={'key2': 'value2'})),
202+
]
203+
204+
# Exercise
205+
result = get_data_parts(parts)
206+
207+
# Verify
208+
assert result == [{'key1': 'value1'}, {'key2': 'value2'}]
209+
210+
def test_get_data_parts_mixed_parts(self):
211+
# Setup
212+
parts = [
213+
Part(root=TextPart(text='some text')),
214+
Part(root=DataPart(data={'key1': 'value1'})),
215+
Part(root=DataPart(data={'key2': 'value2'})),
216+
]
217+
218+
# Exercise
219+
result = get_data_parts(parts)
220+
221+
# Verify
222+
assert result == [{'key1': 'value1'}, {'key2': 'value2'}]
223+
224+
def test_get_data_parts_no_data_parts(self):
225+
# Setup
226+
parts = [
227+
Part(root=TextPart(text='some text')),
228+
]
229+
230+
# Exercise
231+
result = get_data_parts(parts)
232+
233+
# Verify
234+
assert result == []
235+
236+
def test_get_data_parts_empty_list(self):
237+
# Setup
238+
parts = []
239+
240+
# Exercise
241+
result = get_data_parts(parts)
242+
243+
# Verify
244+
assert result == []
245+
246+
247+
class TestGetFileParts:
248+
def test_get_file_parts_single_file_part(self):
249+
# Setup
250+
file_with_uri = FileWithUri(uri='file://path/to/file', mimeType='text/plain')
251+
parts = [Part(root=FilePart(file=file_with_uri))]
252+
253+
# Exercise
254+
result = get_file_parts(parts)
255+
256+
# Verify
257+
assert result == [file_with_uri]
258+
259+
def test_get_file_parts_multiple_file_parts(self):
260+
# Setup
261+
file_with_uri1 = FileWithUri(uri='file://path/to/file1', mimeType='text/plain')
262+
file_with_bytes = FileWithBytes(
263+
bytes='ZmlsZSBjb250ZW50', mimeType='application/octet-stream' # 'file content'
264+
)
265+
parts = [
266+
Part(root=FilePart(file=file_with_uri1)),
267+
Part(root=FilePart(file=file_with_bytes)),
268+
]
269+
270+
# Exercise
271+
result = get_file_parts(parts)
272+
273+
# Verify
274+
assert result == [file_with_uri1, file_with_bytes]
275+
276+
def test_get_file_parts_mixed_parts(self):
277+
# Setup
278+
file_with_uri = FileWithUri(uri='file://path/to/file', mimeType='text/plain')
279+
parts = [
280+
Part(root=TextPart(text='some text')),
281+
Part(root=FilePart(file=file_with_uri)),
282+
]
283+
284+
# Exercise
285+
result = get_file_parts(parts)
286+
287+
# Verify
288+
assert result == [file_with_uri]
289+
290+
def test_get_file_parts_no_file_parts(self):
291+
# Setup
292+
parts = [
293+
Part(root=TextPart(text='some text')),
294+
Part(root=DataPart(data={'key': 'value'})),
295+
]
296+
297+
# Exercise
298+
result = get_file_parts(parts)
299+
300+
# Verify
301+
assert result == []
302+
303+
def test_get_file_parts_empty_list(self):
304+
# Setup
305+
parts = []
306+
307+
# Exercise
308+
result = get_file_parts(parts)
309+
310+
# Verify
311+
assert result == []
312+
313+
181314
class TestGetMessageText:
182315
def test_get_message_text_single_part(self):
183316
# Setup

0 commit comments

Comments
 (0)