refactor(fudai): 拆出保存详情成功 + 提取 future_ts(1556→1529,-27 行)
- save_first_read_detail_success:筛选通过后保存 detail + 标记 first_read + 写日志 - extract_future_ts_from_detail:从 detail 的 countdown_tuple 中提取 future_ts 新增 7 个单元测试,1201 → 1208 用例全过。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
be95d9c279
commit
cc164a192f
3 files changed
+104
-29
No files matched your search
@@ -723,3 +723,66 @@ def test_log_entry_flags_swallows_exception():
|
||||
a = MagicMock()
|
||||
a._log_kv.side_effect = RuntimeError("boom")
|
||||
fudai_detail_blocks.log_entry_flags(a)
|
||||
|
||||
|
||||
# ---- save_first_read_detail_success ---- #
|
||||
|
||||
def test_save_first_read_sets_flags_and_content():
|
||||
a = MagicMock()
|
||||
detail = ("content_x", "x", "x", "x", 5.0, ("s", _time.time() + 100, 100))
|
||||
fudai_detail_blocks.save_first_read_detail_success(a, detail)
|
||||
assert a._last_fudai_detail_tuple == detail
|
||||
assert a._fudai_detail_first_read is True
|
||||
assert a._current_fudai_content == "content_x"
|
||||
|
||||
|
||||
def test_save_first_read_logs_success():
|
||||
a = MagicMock()
|
||||
detail = ("c", "x", "x", "x", 10.0, ("s", _time.time() + 100, 100))
|
||||
fudai_detail_blocks.save_first_read_detail_success(a, detail)
|
||||
success_calls = [
|
||||
c for c in a._log_kv.call_args_list
|
||||
if len(c.args) >= 2 and "福袋详情识别成功" in c.args[1]
|
||||
]
|
||||
assert len(success_calls) == 1
|
||||
|
||||
|
||||
def test_save_first_read_swallows_exception():
|
||||
a = MagicMock()
|
||||
a._log_kv.side_effect = RuntimeError("boom")
|
||||
fudai_detail_blocks.save_first_read_detail_success(a, ("c",))
|
||||
|
||||
|
||||
# ---- extract_future_ts_from_detail ---- #
|
||||
|
||||
def test_extract_future_ts_with_valid_detail():
|
||||
a = MagicMock()
|
||||
a._current_fudai_future_ts = 0.0
|
||||
target_ts = _time.time() + 100
|
||||
detail = ("c", "x", "x", "x", 5.0, ("s", target_ts, 100))
|
||||
fudai_detail_blocks.extract_future_ts_from_detail(a, detail)
|
||||
assert a._current_fudai_future_ts == target_ts
|
||||
|
||||
|
||||
def test_extract_future_ts_short_tuple_no_change():
|
||||
a = MagicMock()
|
||||
a._current_fudai_future_ts = 999.0
|
||||
detail = ("only_one_elem",)
|
||||
fudai_detail_blocks.extract_future_ts_from_detail(a, detail)
|
||||
assert a._current_fudai_future_ts == 999.0
|
||||
|
||||
|
||||
def test_extract_future_ts_invalid_countdown_no_change():
|
||||
a = MagicMock()
|
||||
a._current_fudai_future_ts = 999.0
|
||||
detail = ("c", "x", "x", "x", 5.0, "not_a_tuple")
|
||||
fudai_detail_blocks.extract_future_ts_from_detail(a, detail)
|
||||
assert a._current_fudai_future_ts == 999.0
|
||||
|
||||
|
||||
def test_extract_future_ts_zero_value_no_change():
|
||||
a = MagicMock()
|
||||
a._current_fudai_future_ts = 999.0
|
||||
detail = ("c", "x", "x", "x", 5.0, ("s", 0, 0))
|
||||
fudai_detail_blocks.extract_future_ts_from_detail(a, detail)
|
||||
assert a._current_fudai_future_ts == 999.0
|
||||
Reference in new issue
Block a user