From 2c6f024a24a949187d9f06b94f70d9a7705ef80b Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 1 Jun 2026 21:18:28 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E8=A1=A5=E5=9B=9E=E9=A1=B6?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E6=98=A0=E5=B0=84=E4=B8=8E=E5=90=8C=E6=88=BF?= =?UTF-8?q?=E4=B8=89=E8=BF=9E=E6=98=A0=E5=B0=84=E5=9B=9E=E5=BD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_handlers.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_handlers.py b/tests/test_handlers.py index 87a8de8..d34f824 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -119,6 +119,37 @@ class TestSwipeHandler: assert int(getattr(a, "room_pos", 0) or 0) == 5 assert bool(getattr(a, "_record_title_before_swipe_up", False)) is False + def test_reset_to_top_keep_mapping_does_not_clear_map(self): + """回顶后应保留运行时映射表。""" + from douyin.handlers.douyin_swipe_handler import SwipeHandler + + class _A: + pass + + a = _A() + a._resetting_after_swipes = False + a.room_pos = 3 + a._swipe_times = 9 + a._just_switched_room = False + a._room_pos_to_title_map = { + 0: {"title": "A", "title_raw": "A"}, + 1: {"title": "B", "title_raw": "B"}, + 2: {"title": "C", "title_raw": "C"}, + } + a._log_kv = MagicMock(return_value=None) + a.operation = MagicMock() + a.operation.delay = MagicMock(return_value=None) + + with patch("douyin.handlers.douyin_swipe_ops.swipe_down_back_live") as mock_down: + ok = SwipeHandler.reset_to_top_keep_mapping(a, reason="ut", min_back_times=1) + + assert ok is True + assert mock_down.call_count >= 1 + assert int(getattr(a, "room_pos", -1)) == 0 + assert isinstance(a._room_pos_to_title_map, dict) + assert len(a._room_pos_to_title_map) == 3 + assert 0 in a._room_pos_to_title_map and 2 in a._room_pos_to_title_map + class TestSwipeOps: """douyin_swipe_ops 模块测试。"""