refactor(fudai): 拆出 _handle_in_fudai_detail 数据验证失败善后(3663→3632,-31 行)
handle_validation_failure_cleanup:步骤2 数据验证失败时关闭详情页 + 写日志 + 清除任务数量标志(与 detail_is_none 共享同一套清理动作)。 新增 2 个单元测试覆盖正常路径与 close 异常分支,1071 → 1073 用例全过。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b6cd3ac8a3
commit
2d971ca7d8
3 files changed
+79
-33
No files matched your search
@@ -93,3 +93,31 @@ def test_detail_is_none_swallows_log_exceptions():
|
||||
# 应当不抛错
|
||||
result = fudai_detail_blocks.handle_detail_is_none(a, _time.time())
|
||||
assert result is True
|
||||
|
||||
|
||||
# ---- handle_validation_failure_cleanup ---- #
|
||||
|
||||
def test_validation_cleanup_closes_detail_and_logs():
|
||||
a = MagicMock()
|
||||
a._log_kv = MagicMock()
|
||||
a._fudai_detail_task_count_from_stage = 7
|
||||
with patch("douyin.fudai.douyin_fudai_detail.close_fudai_detail") as cd:
|
||||
fudai_detail_blocks.handle_validation_failure_cleanup(
|
||||
a, _time.time() - 0.5, _time.time() - 0.3
|
||||
)
|
||||
cd.assert_called_once_with(a)
|
||||
assert a._fudai_detail_task_count_from_stage is None
|
||||
# 至少 3 次日志:步骤2完成 / 清除标志 / 完成(数据验证失败)
|
||||
assert a._log_kv.call_count >= 2
|
||||
|
||||
|
||||
def test_validation_cleanup_close_failure_does_not_break():
|
||||
a = MagicMock()
|
||||
with patch(
|
||||
"douyin.fudai.douyin_fudai_detail.close_fudai_detail",
|
||||
side_effect=RuntimeError("boom"),
|
||||
):
|
||||
fudai_detail_blocks.handle_validation_failure_cleanup(
|
||||
a, _time.time(), _time.time()
|
||||
)
|
||||
assert a._fudai_detail_task_count_from_stage is None
|
||||
Reference in new issue
Block a user