|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
8 | | -from a2a.types.a2a_pb2 import Artifact, Message, Part, Role, TaskState, GetTaskRequest, SendMessageConfiguration |
| 8 | +from a2a.types.a2a_pb2 import ( |
| 9 | + Artifact, |
| 10 | + Message, |
| 11 | + Part, |
| 12 | + Role, |
| 13 | + TaskState, |
| 14 | + GetTaskRequest, |
| 15 | + SendMessageConfiguration, |
| 16 | +) |
9 | 17 | from a2a.utils.task import ( |
10 | 18 | apply_history_length, |
11 | 19 | completed_task, |
@@ -214,51 +222,54 @@ def test_decode_page_token_fails(self): |
214 | 222 | ) |
215 | 223 |
|
216 | 224 |
|
217 | | -if __name__ == '__main__': |
218 | | - unittest.main() |
219 | | - |
220 | | - |
221 | | - |
222 | 225 | class TestApplyHistoryLength(unittest.TestCase): |
223 | 226 | def setUp(self): |
224 | | - # Create a task with some history |
225 | 227 | self.history = [ |
226 | | - Message(message_id=str(i), role=Role.ROLE_USER, parts=[Part(text=f'msg {i}')]) |
| 228 | + Message( |
| 229 | + message_id=str(i), |
| 230 | + role=Role.ROLE_USER, |
| 231 | + parts=[Part(text=f'msg {i}')], |
| 232 | + ) |
227 | 233 | for i in range(5) |
228 | 234 | ] |
229 | 235 | artifacts = [Artifact(artifact_id='a1', parts=[Part(text='a')])] |
230 | 236 | self.task = completed_task( |
231 | 237 | task_id='t1', |
232 | 238 | context_id='c1', |
233 | 239 | artifacts=artifacts, |
234 | | - history=self.history |
| 240 | + history=self.history, |
235 | 241 | ) |
236 | 242 |
|
237 | 243 | def test_none_config_returns_full_history(self): |
238 | | - # Test None (no limit) - config is None |
239 | 244 | result = apply_history_length(self.task, None) |
240 | 245 | self.assertEqual(len(result.history), 5) |
241 | 246 | self.assertEqual(result.history, self.history) |
242 | 247 |
|
243 | 248 | def test_unset_history_length_returns_full_history(self): |
244 | | - # Test unset (HasField returns False) |
245 | | - # Using GetTaskRequest as it has history_length field |
246 | 249 | result = apply_history_length(self.task, GetTaskRequest()) |
247 | 250 | self.assertEqual(len(result.history), 5) |
248 | 251 | self.assertEqual(result.history, self.history) |
249 | 252 |
|
250 | 253 | def test_positive_history_length_truncates(self): |
251 | | - # Test > 0 (partial) |
252 | | - result = apply_history_length(self.task, GetTaskRequest(history_length=2)) |
| 254 | + result = apply_history_length( |
| 255 | + self.task, GetTaskRequest(history_length=2) |
| 256 | + ) |
253 | 257 | self.assertEqual(len(result.history), 2) |
254 | 258 | self.assertEqual(result.history, self.history[-2:]) |
255 | 259 |
|
256 | 260 | def test_large_history_length_returns_full_history(self): |
257 | | - result = apply_history_length(self.task, GetTaskRequest(history_length=10)) |
| 261 | + result = apply_history_length( |
| 262 | + self.task, GetTaskRequest(history_length=10) |
| 263 | + ) |
258 | 264 | self.assertEqual(len(result.history), 5) |
259 | 265 | self.assertEqual(result.history, self.history) |
260 | 266 |
|
261 | 267 | def test_zero_history_length_returns_empty_history(self): |
262 | | - result = apply_history_length(self.task, SendMessageConfiguration(history_length=0)) |
| 268 | + result = apply_history_length( |
| 269 | + self.task, SendMessageConfiguration(history_length=0) |
| 270 | + ) |
263 | 271 | self.assertEqual(len(result.history), 0) |
264 | 272 |
|
| 273 | + |
| 274 | +if __name__ == '__main__': |
| 275 | + unittest.main() |
0 commit comments