Files
douyi_guaji_main/tests/integration/test_config_loading.py
T
Your Name e68f1dd3de 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.
2025-12-23 02:38:51 +08:00

77 lines
2.0 KiB
Python

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