feat: Refactor coverage management and enhance logging functionality
- Removed the `.coverage` file from the repository to streamline coverage management. - Updated `.gitignore` to exclude coverage-related files and directories, ensuring a cleaner project structure. - Introduced new scripts for checking GPU availability and detecting GUI parameter conflicts, enhancing the overall functionality of the application. - Improved logging mechanisms across various modules to support better debugging and monitoring. - Added comprehensive documentation for new features and updated existing markdown files for clarity.
This commit is contained in:
1 parent
539e580147
commit
e68f1dd3de
70 files changed
+62590
-10791
No files matched your search
@@ -1,2 +1,18 @@
|
||||
"""单元测试模块"""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ douyin_fudai_core模块测试
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import time
|
||||
from unittest.mock import Mock, patch
|
||||
from douyin_fudai_core import (
|
||||
should_skip_fudai_by_config,
|
||||
@@ -10,6 +11,31 @@ from douyin_fudai_core import (
|
||||
)
|
||||
|
||||
|
||||
def _create_detail_tuple(
|
||||
content: str = "测试福袋",
|
||||
time_text: str = "01:00",
|
||||
participants: int = 100,
|
||||
copies: int = 1,
|
||||
prize_value_yuan: float = 10.0,
|
||||
countdown_seconds: float = 60.0,
|
||||
) -> tuple:
|
||||
"""创建测试用的 detail 元组
|
||||
|
||||
detail 格式: (content, time_text, participants, copies, prize_value_yuan, (countdown_start, countdown_end))
|
||||
"""
|
||||
now = time.time()
|
||||
countdown_start = now
|
||||
countdown_end = now + countdown_seconds
|
||||
return (
|
||||
content,
|
||||
time_text,
|
||||
participants,
|
||||
copies,
|
||||
prize_value_yuan,
|
||||
(countdown_start, countdown_end),
|
||||
)
|
||||
|
||||
|
||||
class TestShouldSkipFudaiByConfig:
|
||||
"""福袋筛选配置测试"""
|
||||
|
||||
@@ -17,68 +43,44 @@ class TestShouldSkipFudaiByConfig:
|
||||
"""测试按最小价值筛选"""
|
||||
mock_analyser.min_prize_value_yuan = 10.0
|
||||
# 价值低于最小值,应该跳过
|
||||
result = should_skip_fudai_by_config(
|
||||
mock_analyser,
|
||||
prize_value_yuan=5.0,
|
||||
participants=100,
|
||||
countdown_seconds=60
|
||||
)
|
||||
assert result is True
|
||||
detail = _create_detail_tuple(prize_value_yuan=5.0, participants=100, countdown_seconds=60)
|
||||
skip, reason = should_skip_fudai_by_config(mock_analyser, detail)
|
||||
assert skip is True
|
||||
|
||||
def test_not_skip_by_value(self, mock_analyser):
|
||||
"""测试价值满足要求,不跳过"""
|
||||
mock_analyser.min_prize_value_yuan = 10.0
|
||||
result = should_skip_fudai_by_config(
|
||||
mock_analyser,
|
||||
prize_value_yuan=20.0,
|
||||
participants=100,
|
||||
countdown_seconds=60
|
||||
)
|
||||
assert result is False
|
||||
detail = _create_detail_tuple(prize_value_yuan=20.0, participants=100, countdown_seconds=60)
|
||||
skip, reason = should_skip_fudai_by_config(mock_analyser, detail)
|
||||
assert skip is False
|
||||
|
||||
def test_skip_by_min_participants(self, mock_analyser):
|
||||
"""测试按最小参与人数筛选"""
|
||||
mock_analyser.min_participants = 1000
|
||||
result = should_skip_fudai_by_config(
|
||||
mock_analyser,
|
||||
prize_value_yuan=10.0,
|
||||
participants=500,
|
||||
countdown_seconds=60
|
||||
)
|
||||
assert result is True
|
||||
detail = _create_detail_tuple(prize_value_yuan=10.0, participants=500, countdown_seconds=60)
|
||||
skip, reason = should_skip_fudai_by_config(mock_analyser, detail)
|
||||
assert skip is True
|
||||
|
||||
def test_skip_by_max_participants(self, mock_analyser):
|
||||
"""测试按最大参与人数筛选"""
|
||||
mock_analyser.max_participants = 100
|
||||
result = should_skip_fudai_by_config(
|
||||
mock_analyser,
|
||||
prize_value_yuan=10.0,
|
||||
participants=200,
|
||||
countdown_seconds=60
|
||||
)
|
||||
assert result is True
|
||||
detail = _create_detail_tuple(prize_value_yuan=10.0, participants=200, countdown_seconds=60)
|
||||
skip, reason = should_skip_fudai_by_config(mock_analyser, detail)
|
||||
assert skip is True
|
||||
|
||||
def test_skip_by_countdown_gt(self, mock_analyser):
|
||||
"""测试按倒计时大于阈值筛选"""
|
||||
mock_analyser.skip_if_countdown_gt_seconds = 60
|
||||
result = should_skip_fudai_by_config(
|
||||
mock_analyser,
|
||||
prize_value_yuan=10.0,
|
||||
participants=100,
|
||||
countdown_seconds=120
|
||||
)
|
||||
assert result is True
|
||||
detail = _create_detail_tuple(prize_value_yuan=10.0, participants=100, countdown_seconds=120)
|
||||
skip, reason = should_skip_fudai_by_config(mock_analyser, detail)
|
||||
assert skip is True
|
||||
|
||||
def test_skip_by_countdown_lt(self, mock_analyser):
|
||||
"""测试按倒计时小于阈值筛选"""
|
||||
mock_analyser.skip_if_countdown_lt_seconds = 10
|
||||
result = should_skip_fudai_by_config(
|
||||
mock_analyser,
|
||||
prize_value_yuan=10.0,
|
||||
participants=100,
|
||||
countdown_seconds=5
|
||||
)
|
||||
assert result is True
|
||||
detail = _create_detail_tuple(prize_value_yuan=10.0, participants=100, countdown_seconds=5)
|
||||
skip, reason = should_skip_fudai_by_config(mock_analyser, detail)
|
||||
assert skip is True
|
||||
|
||||
|
||||
class TestBasicJoinDecision:
|
||||
@@ -90,23 +92,20 @@ class TestBasicJoinDecision:
|
||||
mock_analyser.min_participants = 0
|
||||
mock_analyser.max_participants = 0
|
||||
|
||||
with patch('douyin_fudai_core.should_skip_fudai_by_config', return_value=False):
|
||||
result = basic_join_decision(
|
||||
mock_analyser,
|
||||
prize_value_yuan=10.0,
|
||||
participants=100,
|
||||
countdown_seconds=60
|
||||
)
|
||||
assert result is True
|
||||
detail = _create_detail_tuple(prize_value_yuan=10.0, participants=100, countdown_seconds=60)
|
||||
with patch('douyin_fudai_core.should_skip_fudai_by_config', return_value=(False, "ok")):
|
||||
with patch('douyin_fudai_core.attend_choujiang', return_value=True):
|
||||
result = basic_join_decision(mock_analyser, detail)
|
||||
assert result is True
|
||||
|
||||
def test_join_decision_negative(self, mock_analyser):
|
||||
"""测试决定不参与"""
|
||||
with patch('douyin_fudai_core.should_skip_fudai_by_config', return_value=True):
|
||||
result = basic_join_decision(
|
||||
mock_analyser,
|
||||
prize_value_yuan=10.0,
|
||||
participants=100,
|
||||
countdown_seconds=60
|
||||
)
|
||||
detail = _create_detail_tuple(prize_value_yuan=10.0, participants=100, countdown_seconds=60)
|
||||
with patch('douyin_fudai_core.should_skip_fudai_by_config', return_value=(True, "test_reason")):
|
||||
result = basic_join_decision(mock_analyser, detail)
|
||||
assert result is False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -97,3 +97,19 @@ class TestExtractParticipantsCount:
|
||||
assert extract_participants_count("") == 0
|
||||
assert extract_participants_count(None) == 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -68,3 +68,19 @@ class TestParseCountdownSeconds:
|
||||
except (ValueError, AttributeError):
|
||||
pass # 如果抛出异常也是可以接受的
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -27,64 +27,23 @@ class TestRunParams:
|
||||
y_pianyi=0,
|
||||
needswitch=False,
|
||||
wait_minutes=5,
|
||||
min_prize_value_yuan=1.0,
|
||||
min_participants=0,
|
||||
max_participants=0,
|
||||
skip_if_countdown_gt_seconds=600,
|
||||
reset_after_swipes_enabled=False,
|
||||
reset_after_swipes=10,
|
||||
min_prize_value_yuan=1.0,
|
||||
min_participants=0,
|
||||
max_participants=0,
|
||||
auto_join_fansclub=False,
|
||||
fansclub_fail_action="stay",
|
||||
high_value_fudai_enabled=False,
|
||||
high_value_fudai_threshold_yuan=1000.0,
|
||||
high_value_fudai_join_ahead_seconds=120,
|
||||
high_value_fudai_max_swipe_back=60,
|
||||
high_value_fudai_max_reservations=5,
|
||||
high_value_fudai_after_action="continue",
|
||||
high_value_room_revisit_enabled=True,
|
||||
high_value_room_revisit_only_current_run=False,
|
||||
reservation_back_verify_enabled=True,
|
||||
reservation_back_swipe_delay=0.6,
|
||||
reservation_preempt_min_value=0.0,
|
||||
fudai_find_max_attempts=5,
|
||||
fudai_icon_retry_delay_seconds=0.6,
|
||||
fudai_icon_max_wait_seconds=5.0,
|
||||
yanghao_enabled=False,
|
||||
yanghao_enable_actions=False,
|
||||
yanghao_recommend_duration_seconds=60,
|
||||
yanghao_recommend_interval_seconds=0,
|
||||
yanghao_like_prob=0.15,
|
||||
yanghao_fav_prob=0.05,
|
||||
yanghao_comment_prob=0.0,
|
||||
yanghao_icon_roi_size=180,
|
||||
yanghao_icon_match_threshold=0.72,
|
||||
yanghao_like_template_path="assets/like.png",
|
||||
yanghao_fav_template_path="assets/fav.png",
|
||||
yanghao_after_dwell_swipe_direction="up",
|
||||
yanghao_after_dwell_swipe_distance_px=900,
|
||||
yanghao_like_icon_x=0,
|
||||
yanghao_like_icon_y=-1,
|
||||
yanghao_fav_icon_x=-1,
|
||||
yanghao_fav_icon_y=0,
|
||||
yanghao_comment_btn_x=0,
|
||||
yanghao_comment_btn_y=-1,
|
||||
yanghao_comment_input_x=0,
|
||||
yanghao_comment_input_y=0,
|
||||
yanghao_comment_send_x=0,
|
||||
yanghao_comment_send_y=-1,
|
||||
yanghao_comment_close_x=0,
|
||||
yanghao_comment_close_y=0,
|
||||
yanghao_comment_texts=[],
|
||||
yanghao_like_keywords=[],
|
||||
yanghao_fav_keywords=[],
|
||||
stage_diag_max_time=15.0,
|
||||
stage_diag_max_step_time=4.0,
|
||||
live_room_match_threshold=0.7,
|
||||
enable_ocr_mode1=False,
|
||||
fudai_template_match_enabled=False,
|
||||
fudai_template_match_threshold=0.7,
|
||||
lucky_draw_red_ratio_threshold=0.8,
|
||||
skip_if_countdown_lt_seconds=5,
|
||||
)
|
||||
|
||||
assert params.device_id == "test_device"
|
||||
@@ -136,3 +95,7 @@ class TestRunner:
|
||||
# 简化处理
|
||||
assert True # 占位测试
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -31,3 +31,19 @@ class TestPathConfig:
|
||||
# 实际测试中可能需要mock文件系统操作
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,3 +43,19 @@ class TestVersion:
|
||||
assert VERSION in captured.out
|
||||
assert RELEASE_DATE in captured.out
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user