feat: Add coverage report generation and enhance testing framework
- Introduced a new `.coverage` file for tracking test coverage metrics. - Added `pytest.ini` configuration for streamlined testing setup, including coverage reporting and logging options. - Created `requirements-test.txt` to manage testing dependencies, ensuring a consistent testing environment. - Implemented a `run_tests.py` script to facilitate running tests with various options, including unit and integration tests. - Established a structured testing directory with unit and integration tests, enhancing code reliability and maintainability. - Updated documentation to reflect new testing procedures and configurations.
This commit is contained in:
1 parent
ce4a332dc0
commit
539e580147
44 files changed
+11824
-9501
No files matched your search
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
配置加载集成测试
|
||||
"""
|
||||
|
||||
import pytest
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user