test(test_report): 修复类型注解并简化类型声明
1. 为error参数添加Optional类型注解 2. 显式指定TaskSpec和TaskResult的泛型参数,移除冗余的类型忽略注释
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import pyflowx as px
|
import pyflowx as px
|
||||||
from pyflowx.task import TaskResult, TaskSpec, TaskStatus
|
from pyflowx.task import TaskResult, TaskSpec, TaskStatus
|
||||||
@@ -16,21 +17,21 @@ def _make_result(
|
|||||||
name: str = "a",
|
name: str = "a",
|
||||||
status: TaskStatus = TaskStatus.SUCCESS,
|
status: TaskStatus = TaskStatus.SUCCESS,
|
||||||
value: object = 42,
|
value: object = 42,
|
||||||
error: object = None,
|
error: Optional[object] = None,
|
||||||
duration: float = 0.5,
|
duration: float = 0.5,
|
||||||
attempts: int = 1,
|
attempts: int = 1,
|
||||||
) -> TaskResult[object]:
|
) -> TaskResult[object]:
|
||||||
spec: TaskSpec[object] = TaskSpec(name, _fn) # type: ignore[arg-type]
|
spec: TaskSpec[object] = TaskSpec[object](name, _fn)
|
||||||
start = datetime(2024, 1, 1, 0, 0, 0)
|
start = datetime(2024, 1, 1, 0, 0, 0)
|
||||||
# 用 timedelta 精确表达秒数,避免 int() 截断小数
|
# 用 timedelta 精确表达秒数,避免 int() 截断小数
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
end = start + timedelta(seconds=duration) if duration else None
|
end = start + timedelta(seconds=duration) if duration else None
|
||||||
return TaskResult(
|
return TaskResult[object](
|
||||||
spec=spec,
|
spec=spec,
|
||||||
status=status,
|
status=status,
|
||||||
value=value, # type: ignore[arg-type]
|
value=value,
|
||||||
error=error, # type: ignore[arg-type]
|
error=error,
|
||||||
attempts=attempts,
|
attempts=attempts,
|
||||||
started_at=start,
|
started_at=start,
|
||||||
finished_at=end,
|
finished_at=end,
|
||||||
|
|||||||
Reference in New Issue
Block a user