25 lines
1.2 KiB
Python
25 lines
1.2 KiB
Python
from datetime import datetime, timezone
|
|
from types import SimpleNamespace
|
|
from unittest import TestCase
|
|
|
|
from system_manage.ai_hub_progress import task_progress
|
|
|
|
|
|
class TaskSectionProgressTests(TestCase):
|
|
def test_failed_and_rendering_retain_organize_progress(self):
|
|
now = datetime.now(timezone.utc)
|
|
detail = {'partial_markdown': '# One\n\n- Done\n\n# Two\n\n> 待总结',
|
|
'completed_sections': 1, 'total_sections': 2}
|
|
for status, steps in (
|
|
('FAILED', [{'type': 'organize', 'status': 'FAILED', 'progress': detail}]),
|
|
('RUNNING', [{'type': 'organize', 'status': 'SUCCESS', 'progress': detail},
|
|
{'type': 'render', 'status': 'RUNNING', 'progress': {'stage': '生成中'}}]),
|
|
('SUCCESS', [{'type': 'organize', 'status': 'SUCCESS', 'progress': detail}]),
|
|
):
|
|
with self.subTest(status=status):
|
|
task = SimpleNamespace(status=status, steps=steps, snapshot={'nodes': [{}, {}]},
|
|
created_at=now, started_at=now, finished_at=now)
|
|
result = task_progress(task)
|
|
for key, value in detail.items():
|
|
self.assertEqual(result[key], value)
|