Files
douyi_guaji_main/tests/integration/test_config_loading.py
T
Your Name f92933641f feat: Enhance documentation and clean up code structure
- Added comprehensive documentation for the unified screenshot and score recording process in the new markdown file.
- Improved existing markdown files by adding spacing for better readability.
- Cleaned up code by removing unnecessary blank lines across various scripts, enhancing overall code clarity.
- Updated configuration settings to reflect recent changes and ensure consistency across the project.
- Enhanced logging mechanisms to support better debugging and monitoring.
2025-12-25 16:11:25 +08:00

86 lines
2.1 KiB
Python

"""
配置加载集成测试
"""
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