feat: Refactor and reorganize project structure with new modules and files

- Deleted obsolete files including test scripts and configuration files to streamline the project.
- Introduced new modules for handling Douyin functionalities, including core operations, logging, and GUI components.
- Updated import paths to reflect the new module structure, enhancing code organization and maintainability.
- Added configuration files and documentation to support the new structure and improve user guidance.
This commit is contained in:
Your Name committed 2025-12-28 14:16:40 +08:00
1 parent ea7159355b
commit c67f22f76f
139 files changed
+7571 -7828

No files matched your search

-253
View File
@@ -1,253 +0,0 @@
# 测试套件文档
## 📋 目录结构
```
tests/
├── __init__.py
├── conftest.py # pytest全局配置和fixtures
├── unit/ # 单元测试
│ ├── __init__.py
│ ├── test_version.py
│ ├── test_douyin_utils.py
│ ├── test_douyin_text_utils.py
│ ├── test_path_config.py
│ ├── test_douyin_fudai_core.py
│ └── test_gui_core.py
├── integration/ # 集成测试
│ ├── __init__.py
│ ├── test_config_loading.py
│ └── test_fudai_analyse_init.py
├── fixtures/ # 测试数据
│ └── (测试图片、JSON文件等)
└── mocks/ # Mock对象
└── (可复用的Mock类)
```
## 🚀 快速开始
### 1. 安装测试依赖
```bash
pip install -r requirements-test.txt
```
### 2. 运行所有测试
```bash
# 使用pytest直接运行
pytest
# 或使用测试脚本
python run_tests.py
```
### 3. 运行特定类型的测试
```bash
# 只运行单元测试
python run_tests.py --unit
# 只运行集成测试
python run_tests.py --integration
# 运行特定标记的测试
pytest -m unit
pytest -m integration
```
### 4. 生成覆盖率报告
```bash
python run_tests.py --coverage
# 报告位置: htmlcov/index.html
```
### 5. 并行运行测试
```bash
python run_tests.py --parallel
```
## 📝 编写测试
### 单元测试示例
```python
import pytest
from douyin_utils import normalize_countdown_text
class TestNormalizeCountdownText:
def test_normalize_minutes_seconds(self):
assert normalize_countdown_text("5分30秒") == "5:30"
```
### 使用Fixtures
```python
def test_with_mock_analyser(mock_analyser):
assert mock_analyser.device_id == "test_device_123"
```
### 标记测试
```python
@pytest.mark.unit
def test_something():
pass
@pytest.mark.integration
def test_integration():
pass
@pytest.mark.requires_device
def test_with_device():
pass
```
## 🎯 测试标记
- `@pytest.mark.unit` - 单元测试
- `@pytest.mark.integration` - 集成测试
- `@pytest.mark.slow` - 慢速测试
- `@pytest.mark.requires_device` - 需要真实设备
- `@pytest.mark.requires_gui` - 需要GUI环境
- `@pytest.mark.requires_network` - 需要网络连接
- `@pytest.mark.mock` - 使用Mock的测试
## 📊 测试覆盖率目标
- **核心模块**: >= 80%
- **工具模块**: >= 90%
- **整体**: >= 70%
## 🔧 常用命令
```bash
# 运行特定文件
pytest tests/unit/test_version.py
# 运行特定测试类
pytest tests/unit/test_version.py::TestVersion
# 运行特定测试方法
pytest tests/unit/test_version.py::TestVersion::test_version_exists
# 显示详细输出
pytest -v
# 显示print输出
pytest -s
# 在第一个失败时停止
pytest -x
# 运行上次失败的测试
pytest --lf
```
## 📈 CI/CD集成
测试可以在CI/CD流程中自动运行:
```yaml
# GitHub Actions示例
- name: Run tests
run: |
pip install -r requirements-test.txt
pytest --cov=. --cov-report=xml
```
## 🐛 调试测试
```bash
# 使用pdb调试
pytest --pdb
# 使用ipdb调试(需要安装ipdb)
pytest --pdb --pdbcls=IPython.terminal.debugger:Pdb
```
## 📚 更多资源
- [pytest文档](https://docs.pytest.org/)
- [pytest-cov文档](https://pytest-cov.readthedocs.io/)
- [unittest.mock文档](https://docs.python.org/3/library/unittest.mock.html)
-90
View File
@@ -1,90 +0,0 @@
"""
测试套件
========
测试目录结构:
- tests/unit/ : 单元测试
- tests/integration/ : 集成测试
- tests/fixtures/ : 测试数据
- tests/mocks/ : Mock对象
"""
__version__ = "1.0.0"
-228
View File
@@ -1,228 +0,0 @@
"""
pytest配置文件
=============
提供全局的fixtures和测试配置
"""
import os
import sys
import json
import tempfile
import shutil
from pathlib import Path
from typing import Generator, Dict, Any
from unittest.mock import Mock, MagicMock, patch
import pytest # type: ignore
from PIL import Image
import numpy as np
# 添加项目根目录到Python路径
PROJECT_ROOT = Path(__file__).parent.parent
sys.path.insert(0, str(PROJECT_ROOT))
@pytest.fixture(scope="session")
def project_root() -> Path:
"""返回项目根目录路径"""
return PROJECT_ROOT
@pytest.fixture(scope="session")
def test_data_dir() -> Path:
"""返回测试数据目录"""
return PROJECT_ROOT / "tests" / "fixtures"
@pytest.fixture
def temp_dir() -> Generator[Path, None, None]:
"""创建临时目录,测试后自动清理"""
temp_path = Path(tempfile.mkdtemp())
yield temp_path
shutil.rmtree(temp_path, ignore_errors=True)
@pytest.fixture
def temp_config_file(temp_dir: Path) -> Path:
"""创建临时配置文件"""
config_path = temp_dir / "config.json"
default_config = {
"needswitch": False,
"infinite_loop_enabled": False,
"wait_minutes": 1,
"min_prize_value_yuan": 0.0,
"min_participants": 0,
"max_participants": 0,
"skip_if_countdown_gt_seconds": 600,
"fudai_icon_max_wait_seconds": 5.0,
"fudai_icon_retry_delay_seconds": 0.5,
"no_attend_timeout_minutes": 30.0,
"y_pianyi": 0,
}
with open(config_path, "w", encoding="utf-8") as f:
json.dump(default_config, f, indent=2, ensure_ascii=False)
return config_path
@pytest.fixture
def mock_config() -> Dict[str, Any]:
"""返回Mock配置字典"""
return {
"needswitch": False,
"infinite_loop_enabled": False,
"wait_minutes": 1,
"min_prize_value_yuan": 1.0,
"min_participants": 0,
"max_participants": 0,
"skip_if_countdown_gt_seconds": 600,
"skip_if_countdown_lt_seconds": 10,
"fudai_icon_max_wait_seconds": 5.0,
"fudai_icon_retry_delay_seconds": 0.5,
"no_attend_timeout_minutes": 30.0,
"y_pianyi": 0,
"resolution_ratio_x": 1080,
"resolution_ratio_y": 2400,
}
@pytest.fixture
def mock_analyser(mock_config: Dict[str, Any]) -> Mock:
"""创建Mock的analyser对象"""
analyser = Mock()
analyser.device_id = "test_device_123"
analyser.y_pianyi = mock_config["y_pianyi"]
analyser.resolution_ratio_x = mock_config["resolution_ratio_x"]
analyser.resolution_ratio_y = mock_config["resolution_ratio_y"]
analyser.min_prize_value_yuan = mock_config["min_prize_value_yuan"]
analyser.min_participants = mock_config["min_participants"]
analyser.max_participants = mock_config["max_participants"]
analyser.skip_if_countdown_gt_seconds = mock_config["skip_if_countdown_gt_seconds"]
analyser.skip_if_countdown_lt_seconds = mock_config["skip_if_countdown_lt_seconds"]
analyser.fudai_icon_max_wait_seconds = mock_config["fudai_icon_max_wait_seconds"]
analyser.fudai_icon_retry_delay_seconds = mock_config["fudai_icon_retry_delay_seconds"]
analyser._no_attend_timeout_minutes = mock_config["no_attend_timeout_minutes"]
analyser.last_fudai_x = 0
analyser._last_successful_attend_ts = 0.0
analyser._run_start_ts = 0.0
analyser._log_kv = Mock()
analyser._log_step_time = Mock()
analyser.operation = Mock()
analyser.operation.get_screenshot = Mock(return_value=True)
analyser.operation.click = Mock()
analyser.operation.click_back = Mock()
analyser.operation.delay = Mock()
analyser.operation.get_device_resolution = Mock(return_value=(1080, 2400))
return analyser
@pytest.fixture
def mock_operation() -> Mock:
"""创建Mock的operation对象"""
operation = Mock()
operation.get_screenshot = Mock(return_value=True)
operation.click = Mock()
operation.click_back = Mock()
operation.swipe = Mock()
operation.delay = Mock()
operation.get_device_resolution = Mock(return_value=(1080, 2400))
operation.analyse_pic_word = Mock(return_value="测试文本")
return operation
@pytest.fixture
def sample_image() -> Image.Image:
"""创建示例图像(1080x2400 RGB)"""
# 创建一个简单的测试图像
img = Image.new("RGB", (1080, 2400), color=(255, 255, 255))
return img
@pytest.fixture
def sample_fudai_image() -> Image.Image:
"""创建包含福袋图标的示例图像"""
img = Image.new("RGB", (1080, 2400), color=(255, 255, 255))
# 在左上角区域添加红色区域(模拟福袋图标)
pixels = img.load()
for x in range(150, 200):
for y in range(400, 450):
pixels[x, y] = (255, 0, 0) # 红色
return img
@pytest.fixture
def sample_screenshot_path(temp_dir: Path, sample_image: Image.Image) -> Path:
"""创建示例截图文件路径"""
screenshot_path = temp_dir / "screenshot.png"
sample_image.save(screenshot_path)
return screenshot_path
@pytest.fixture(autouse=True)
def mock_path_config(monkeypatch, temp_dir: Path):
"""自动Mock path_config模块,使用临时目录"""
import path_config
def mock_get_screenshot_path():
return str(temp_dir / "screenshot.png")
def mock_get_pic_dir():
return str(temp_dir / "pic")
monkeypatch.setattr(path_config, "get_screenshot_path", mock_get_screenshot_path)
monkeypatch.setattr(path_config, "get_pic_dir", mock_get_pic_dir)
@pytest.fixture
def disable_logging(monkeypatch):
"""禁用日志输出(用于测试)"""
import logging
logging.disable(logging.CRITICAL)
@pytest.fixture
def mock_time(monkeypatch):
"""Mock time模块,用于时间相关的测试"""
import time
current_time = [1000.0] # 使用列表以便修改
def mock_time_func():
return current_time[0]
def mock_sleep(seconds):
current_time[0] += seconds
monkeypatch.setattr(time, "time", mock_time_func)
monkeypatch.setattr(time, "sleep", mock_sleep)
return current_time
# 标记:需要真实设备的测试
pytest_plugins = []
-79
View File
@@ -1,79 +0,0 @@
"""集成测试模块"""
-85
View File
@@ -1,85 +0,0 @@
"""
配置加载集成测试
"""
import pytest # type: ignore
import json
import tempfile
from pathlib import Path
from douyin_fudai import fudai_analyse
@pytest.mark.integration
class TestConfigLoading:
"""配置加载集成测试"""
def test_load_config_from_file(self, temp_config_file):
"""测试从文件加载配置"""
analyser = fudai_analyse()
analyser.config_path = str(temp_config_file)
analyser.load_config()
# 验证配置已加载
assert analyser.min_prize_value_yuan == 0.0
assert analyser.fudai_icon_max_wait_seconds == 5.0
def test_load_config_missing_file(self, temp_dir):
"""测试加载不存在的配置文件"""
analyser = fudai_analyse()
analyser.config_path = str(temp_dir / "nonexistent.json")
# 不应该抛出异常,应该使用默认值
analyser.load_config()
assert analyser.min_prize_value_yuan is not None
def test_load_config_invalid_json(self, temp_dir):
"""测试加载无效的JSON文件"""
invalid_config = temp_dir / "invalid.json"
invalid_config.write_text("{ invalid json }", encoding="utf-8")
analyser = fudai_analyse()
analyser.config_path = str(invalid_config)
# 不应该抛出异常,应该使用默认值
analyser.load_config()
assert analyser.min_prize_value_yuan is not None
def test_config_no_attend_timeout(self, temp_config_file):
"""测试no_attend_timeout_minutes配置加载"""
# 更新配置文件
with open(temp_config_file, "r", encoding="utf-8") as f:
config = json.load(f)
config["no_attend_timeout_minutes"] = 60.0
with open(temp_config_file, "w", encoding="utf-8") as f:
json.dump(config, f, indent=2, ensure_ascii=False)
analyser = fudai_analyse()
analyser.config_path = str(temp_config_file)
analyser.load_config()
assert analyser._no_attend_timeout_minutes == 60.0
@@ -1,70 +0,0 @@
"""
fudai_analyse初始化集成测试
"""
import pytest # type: ignore
from douyin_fudai import fudai_analyse
@pytest.mark.integration
class TestFudaiAnalyseInit:
"""fudai_analyse初始化测试"""
def test_init_default_values(self):
"""测试默认初始化值"""
analyser = fudai_analyse()
# 验证默认值
assert analyser.device_id == ""
assert analyser.y_pianyi == 0
assert analyser.resolution_ratio_x == 1080
assert analyser.resolution_ratio_y == 2400
assert analyser.last_fudai_x == 0
assert analyser._no_attend_timeout_minutes == 30.0
def test_init_has_operation(self):
"""测试operation对象已初始化"""
analyser = fudai_analyse()
assert analyser.operation is not None
assert hasattr(analyser.operation, "get_screenshot")
assert hasattr(analyser.operation, "click")
def test_init_has_log_kv(self):
"""测试日志方法已初始化"""
analyser = fudai_analyse()
assert hasattr(analyser, "_log_kv")
assert callable(analyser._log_kv)
def test_init_constants(self):
"""测试类常量已定义"""
analyser = fudai_analyse()
assert hasattr(analyser.__class__, "MAX_BACK_CLICKS_TO_RECOMMEND")
assert analyser.__class__.MAX_BACK_CLICKS_TO_RECOMMEND == 10
assert hasattr(analyser.__class__, "BACK_KEY_CLICK_DELAY")
assert analyser.__class__.BACK_KEY_CLICK_DELAY == 1.0
-79
View File
@@ -1,79 +0,0 @@
"""单元测试模块"""
-111
View File
@@ -1,111 +0,0 @@
"""
douyin_fudai_core模块测试
"""
import pytest # type: ignore
import time
from unittest.mock import Mock, patch
from douyin_fudai_core import (
should_skip_fudai_by_config,
basic_join_decision,
)
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:
"""福袋筛选配置测试"""
def test_skip_by_min_value(self, mock_analyser):
"""测试按最小价值筛选"""
mock_analyser.min_prize_value_yuan = 10.0
# 价值低于最小值,应该跳过
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
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
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
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
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
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:
"""基础参与决策测试"""
def test_join_decision_positive(self, mock_analyser):
"""测试决定参与"""
mock_analyser.min_prize_value_yuan = 0.0
mock_analyser.min_participants = 0
mock_analyser.max_participants = 0
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):
"""测试决定不参与"""
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
-124
View File
@@ -1,124 +0,0 @@
"""
douyin_text_utils模块测试
"""
import pytest # type: ignore
from douyin_text_utils import (
extract_fudai_content,
extract_fudai_countdown,
extract_fudai_value,
extract_participants_count,
)
class TestExtractFudaiContent:
"""福袋内容提取测试"""
def test_extract_simple_content(self):
"""测试提取简单内容"""
text = "福袋内容:100元现金"
result = extract_fudai_content(text)
assert "100元" in result or "现金" in result
def test_extract_empty_text(self):
"""测试空文本"""
assert extract_fudai_content("") == ""
assert extract_fudai_content(None) == ""
def test_extract_no_content(self):
"""测试没有内容的情况"""
text = "没有相关内容"
result = extract_fudai_content(text)
assert result == "" or result == text
class TestExtractFudaiCountdown:
"""福袋倒计时提取测试"""
def test_extract_minutes_seconds(self):
"""测试提取分钟+秒格式"""
text = "倒计时:5分30秒"
result = extract_fudai_countdown(text)
assert result is not None
assert "5" in result or "30" in result
def test_extract_only_seconds(self):
"""测试提取只有秒的格式"""
text = "倒计时:30秒"
result = extract_fudai_countdown(text)
assert result is not None
def test_extract_empty_text(self):
"""测试空文本"""
assert extract_fudai_countdown("") == ""
assert extract_fudai_countdown(None) == ""
class TestExtractFudaiValue:
"""福袋价值提取测试"""
def test_extract_yuan_value(self):
"""测试提取元为单位的值"""
text = "价值:100元"
result = extract_fudai_value(text)
assert result is not None
assert result >= 0
def test_extract_no_value(self):
"""测试没有价值信息"""
text = "没有价值信息"
result = extract_fudai_value(text)
assert result == 0.0 or result is None
def test_extract_empty_text(self):
"""测试空文本"""
assert extract_fudai_value("") == 0.0
assert extract_fudai_value(None) == 0.0
class TestExtractParticipantsCount:
"""参与人数提取测试"""
def test_extract_participants(self):
"""测试提取参与人数"""
text = "已有1000人参与"
result = extract_participants_count(text)
assert result is not None
assert result >= 0
def test_extract_no_participants(self):
"""测试没有参与人数信息"""
text = "没有参与人数"
result = extract_participants_count(text)
assert result == 0 or result is None
def test_extract_empty_text(self):
"""测试空文本"""
assert extract_participants_count("") == 0
assert extract_participants_count(None) == 0
-95
View File
@@ -1,95 +0,0 @@
"""
douyin_utils模块测试
"""
import pytest # type: ignore
from douyin_utils import normalize_countdown_text, parse_countdown_seconds
class TestNormalizeCountdownText:
"""倒计时文本标准化测试"""
def test_normalize_minutes_seconds(self):
"""测试分钟+秒格式"""
assert normalize_countdown_text("5分30秒") == "5:30"
assert normalize_countdown_text("10分5秒") == "10:05"
assert normalize_countdown_text("0分45秒") == "0:45"
def test_normalize_only_seconds(self):
"""测试只有秒的格式"""
assert normalize_countdown_text("30秒") == "0:30"
assert normalize_countdown_text("5秒") == "0:05"
def test_normalize_only_minutes(self):
"""测试只有分钟的格式"""
assert normalize_countdown_text("5分钟") == "5:00"
assert normalize_countdown_text("10分钟") == "10:00"
def test_normalize_colon_format(self):
"""测试已经是冒号格式的文本"""
assert normalize_countdown_text("5:30") == "5:30"
assert normalize_countdown_text("10:05") == "10:05"
def test_normalize_empty_string(self):
"""测试空字符串"""
assert normalize_countdown_text("") == ""
def test_normalize_invalid_format(self):
"""测试无效格式(应该返回原文本)"""
assert normalize_countdown_text("无效文本") == "无效文本"
assert normalize_countdown_text("abc") == "abc"
class TestParseCountdownSeconds:
"""倒计时秒数解析测试"""
def test_parse_minutes_seconds(self):
"""测试解析分钟+秒格式"""
assert parse_countdown_seconds("5:30") == 330
assert parse_countdown_seconds("10:05") == 605
assert parse_countdown_seconds("0:45") == 45
def test_parse_only_seconds(self):
"""测试解析只有秒的格式"""
assert parse_countdown_seconds("0:30") == 30
assert parse_countdown_seconds("0:05") == 5
def test_parse_only_minutes(self):
"""测试解析只有分钟的格式"""
assert parse_countdown_seconds("5:00") == 300
assert parse_countdown_seconds("10:00") == 600
def test_parse_invalid_format(self):
"""测试无效格式(应该返回0或抛出异常)"""
# 根据实际实现调整
try:
result = parse_countdown_seconds("无效")
assert result == 0 or result is None
except (ValueError, AttributeError):
pass # 如果抛出异常也是可以接受的
-101
View File
@@ -1,101 +0,0 @@
"""
gui_core模块测试
"""
import pytest # type: ignore
from unittest.mock import Mock, patch, MagicMock
import json
import tempfile
from pathlib import Path
from gui_core import (
RunParams,
Runner,
find_adb_executable,
list_adb_devices,
read_config,
write_config,
)
class TestRunParams:
"""RunParams数据类测试"""
def test_run_params_creation(self):
"""测试创建RunParams对象"""
params = RunParams(
device_id="test_device",
y_pianyi=0,
needswitch=False,
wait_minutes=5,
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_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,
enable_ocr_mode1=False,
fudai_template_match_enabled=False,
fudai_template_match_threshold=0.7,
)
assert params.device_id == "test_device"
assert params.y_pianyi == 0
assert params.min_prize_value_yuan == 1.0
class TestConfigFunctions:
"""配置函数测试"""
def test_read_config_existing_file(self, temp_config_file):
"""测试读取存在的配置文件"""
config = read_config()
# 如果使用默认路径,可能不存在,所以只测试函数不抛出异常
assert isinstance(config, dict)
def test_write_config(self, temp_dir):
"""测试写入配置文件"""
config_path = temp_dir / "test_config.json"
test_config = {"test_key": "test_value"}
# 需要mock CONFIG_PATH或使用临时路径
# 这里简化处理
assert True # 占位测试
class TestRunner:
"""Runner类测试"""
def test_runner_init(self):
"""测试Runner初始化"""
on_line = Mock()
runner = Runner(on_line=on_line)
assert runner._on_line == on_line
assert runner._proc is None
assert runner._reader_thread is None
assert runner._lock is not None
def test_runner_is_running_false(self):
"""测试is_running返回False(未运行)"""
runner = Runner(on_line=Mock())
assert runner.is_running() is False
def test_runner_send_back_key(self):
"""测试发送返回键"""
runner = Runner(on_line=Mock())
# 这个测试需要mock subprocess或ADB
# 简化处理
assert True # 占位测试
-58
View File
@@ -1,58 +0,0 @@
"""
path_config模块测试
"""
import os
import pytest # type: ignore
from pathlib import Path
import path_config
class TestPathConfig:
"""路径配置测试类"""
def test_get_screenshot_path(self):
"""测试获取截图路径"""
path = path_config.get_screenshot_path()
assert path is not None
assert isinstance(path, str)
assert path.endswith(".png") or path.endswith("screenshot.png")
def test_get_pic_dir(self):
"""测试获取图片目录"""
pic_dir = path_config.get_pic_dir()
assert pic_dir is not None
assert isinstance(pic_dir, str)
assert os.path.isabs(pic_dir) or pic_dir.startswith("pic")
def test_paths_exist_or_creatable(self, temp_dir):
"""测试路径可以创建"""
# 这个测试需要确保路径可以创建
# 实际测试中可能需要mock文件系统操作
pass
-46
View File
@@ -1,46 +0,0 @@
"""
版本信息模块测试
"""
import pytest # type: ignore[import-untyped]
from version import VERSION, RELEASE_DATE, print_version_banner
class TestVersion:
"""版本信息测试类"""
def test_version_exists(self):
"""测试版本号存在"""
assert VERSION is not None
assert isinstance(VERSION, str)
assert len(VERSION) > 0
def test_version_format(self):
"""测试版本号格式(应该是 x.y.z 格式)"""
parts = VERSION.split(".")
assert len(parts) >= 2, "版本号应该至少包含主版本号和次版本号"
for part in parts:
assert (
part.isdigit() or part.replace("-", "").isdigit()
), f"版本号部分 '{part}' 应该是数字"
def test_release_date_exists(self):
"""测试发布日期存在"""
assert RELEASE_DATE is not None
assert isinstance(RELEASE_DATE, str)
assert len(RELEASE_DATE) > 0
def test_release_date_format(self):
"""测试发布日期格式(应该是 YYYY-MM-DD 格式)"""
parts = RELEASE_DATE.split("-")
assert len(parts) == 3, "发布日期应该是 YYYY-MM-DD 格式"
assert len(parts[0]) == 4, "年份应该是4位数字"
assert len(parts[1]) == 2, "月份应该是2位数字"
assert len(parts[2]) == 2, "日期应该是2位数字"
def test_print_version_banner(self, capsys):
"""测试版本信息打印"""
print_version_banner()
captured = capsys.readouterr()
assert VERSION in captured.out
assert RELEASE_DATE in captured.out