|
4 | 4 |
|
5 | 5 | from a2a.types import (
|
6 | 6 | DataPart,
|
| 7 | + FilePart, |
| 8 | + FileWithBytes, |
| 9 | + FileWithUri, |
7 | 10 | Message,
|
8 | 11 | Part,
|
9 | 12 | Role,
|
10 | 13 | TextPart,
|
11 | 14 | )
|
12 | 15 | from a2a.utils.message import (
|
| 16 | + get_data_parts, |
| 17 | + get_file_parts, |
13 | 18 | get_message_text,
|
14 | 19 | get_text_parts,
|
15 | 20 | new_agent_parts_message,
|
@@ -178,6 +183,141 @@ def test_get_text_parts_empty_list(self):
|
178 | 183 | assert result == []
|
179 | 184 |
|
180 | 185 |
|
| 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( |
| 251 | + uri='file://path/to/file', mimeType='text/plain' |
| 252 | + ) |
| 253 | + parts = [Part(root=FilePart(file=file_with_uri))] |
| 254 | + |
| 255 | + # Exercise |
| 256 | + result = get_file_parts(parts) |
| 257 | + |
| 258 | + # Verify |
| 259 | + assert result == [file_with_uri] |
| 260 | + |
| 261 | + def test_get_file_parts_multiple_file_parts(self): |
| 262 | + # Setup |
| 263 | + file_with_uri1 = FileWithUri( |
| 264 | + uri='file://path/to/file1', mimeType='text/plain' |
| 265 | + ) |
| 266 | + file_with_bytes = FileWithBytes( |
| 267 | + bytes='ZmlsZSBjb250ZW50', |
| 268 | + mimeType='application/octet-stream', # 'file content' |
| 269 | + ) |
| 270 | + parts = [ |
| 271 | + Part(root=FilePart(file=file_with_uri1)), |
| 272 | + Part(root=FilePart(file=file_with_bytes)), |
| 273 | + ] |
| 274 | + |
| 275 | + # Exercise |
| 276 | + result = get_file_parts(parts) |
| 277 | + |
| 278 | + # Verify |
| 279 | + assert result == [file_with_uri1, file_with_bytes] |
| 280 | + |
| 281 | + def test_get_file_parts_mixed_parts(self): |
| 282 | + # Setup |
| 283 | + file_with_uri = FileWithUri( |
| 284 | + uri='file://path/to/file', mimeType='text/plain' |
| 285 | + ) |
| 286 | + parts = [ |
| 287 | + Part(root=TextPart(text='some text')), |
| 288 | + Part(root=FilePart(file=file_with_uri)), |
| 289 | + ] |
| 290 | + |
| 291 | + # Exercise |
| 292 | + result = get_file_parts(parts) |
| 293 | + |
| 294 | + # Verify |
| 295 | + assert result == [file_with_uri] |
| 296 | + |
| 297 | + def test_get_file_parts_no_file_parts(self): |
| 298 | + # Setup |
| 299 | + parts = [ |
| 300 | + Part(root=TextPart(text='some text')), |
| 301 | + Part(root=DataPart(data={'key': 'value'})), |
| 302 | + ] |
| 303 | + |
| 304 | + # Exercise |
| 305 | + result = get_file_parts(parts) |
| 306 | + |
| 307 | + # Verify |
| 308 | + assert result == [] |
| 309 | + |
| 310 | + def test_get_file_parts_empty_list(self): |
| 311 | + # Setup |
| 312 | + parts = [] |
| 313 | + |
| 314 | + # Exercise |
| 315 | + result = get_file_parts(parts) |
| 316 | + |
| 317 | + # Verify |
| 318 | + assert result == [] |
| 319 | + |
| 320 | + |
181 | 321 | class TestGetMessageText:
|
182 | 322 | def test_get_message_text_single_part(self):
|
183 | 323 | # Setup
|
|
0 commit comments