refactor: 优化代码格式,提升可读性和一致性

This commit is contained in:
Your Name committed 2026-01-08 00:15:40 +08:00
1 parent 5738d29bd6
commit 47e1a0cb2c
6 files changed
+172 -89

No files matched your search

+16 -16
View File
@@ -33,14 +33,14 @@ from douyin.reservation.douyin_reservation_verify import validate_back_to_reserv
class MockOperation:
"""模拟操作对象"""
def __init__(self):
self.mock_ocr_result = "美女主播在线" # 默认OCR结果
def get_screenshot(self, device_id):
"""模拟截图"""
pass
def analyse_pic_word(self, cut_name, change_color):
"""模拟OCR识别"""
return self.mock_ocr_result
@@ -179,26 +179,22 @@ def test_error_scenarios():
print("=" * 80)
test_cases = [
{
"name": "正常情况",
"scenario": None,
"description": "无错误情况下的正常回退"
},
{"name": "正常情况", "scenario": None, "description": "无错误情况下的正常回退"},
{
"name": "滑动失败",
"scenario": "swipe_failure",
"description": "模拟滑动操作随机失败"
"description": "模拟滑动操作随机失败",
},
{
"name": "位置更新失败",
"scenario": "position_update_failure",
"description": "模拟位置更新随机失败"
"description": "模拟位置更新随机失败",
},
{
"name": "组合错误",
"scenario": "combined_errors",
"description": "同时模拟滑动和位置更新错误"
}
"description": "同时模拟滑动和位置更新错误",
},
]
# 测试预约项
@@ -240,8 +236,12 @@ def test_error_scenarios():
# 输出结果
print(f"回退结果: {'成功' if result else '失败'}")
print(f"最终位置: {analyser.room_pos}")
print(f"滑动统计: 向上{analyser.swipe_up_count}次, 向下{analyser.swipe_down_count}次")
print(f"错误统计: 滑动失败{analyser.swipe_failures}次, 位置更新失败{analyser.position_update_failures}次")
print(
f"滑动统计: 向上{analyser.swipe_up_count}次, 向下{analyser.swipe_down_count}次"
)
print(
f"错误统计: 滑动失败{analyser.swipe_failures}次, 位置更新失败{analyser.position_update_failures}次"
)
print(f"执行时间: {end_time - start_time:.2f}秒")
# 验证结果
if result and analyser.room_pos == test_reservation["pos_seen"]:
@@ -307,7 +307,7 @@ def test_error_scenarios():
# 修改映射表,使当前位置的标题与预约记录不一致
analyser._room_pos_to_title_map[2] = ("错误的直播间", "错误的直播间")
# 设置OCR识别结果为错误的标题
analyser.operation.mock_ocr_result = "错误的直播间"
@@ -324,4 +324,4 @@ def test_error_scenarios():
if __name__ == "__main__":
test_error_scenarios()
test_error_scenarios()