test(15-00): add test infrastructure placeholders for Phase 15
创建了测试基础设施,为后续计划提供测试框架。 ## 创建的文件 1. **tests/test_processors/test_srt.py** - SRTProcessor 配置集成测试占位符 - TestConfigIntegration 测试类 - 5 个测试占位符(pytest.skip) 2. **tests/test_backward_compat.py** - 向后兼容性测试 - TestBackwardCompatibility 测试类 - 部分测试已实现(来自计划 15-01) - 部分测试占位符(pytest.skip) 3. **tests/conftest.py** - 添加共享 fixtures - temp_env_vars fixture:临时环境变量管理 - mock_kbsettings fixture:Mock KBSettings 实例 - 添加 os 模块导入 ## 偏离说明 计划要求所有测试都是占位符(pytest.skip),但实际上: - test_config.py 已由计划 15-01 实现完整测试 - test_backward_compat.py 有部分实现 原因:计划 15-01 在 15-00 之前执行,导致测试不是占位符。 ## 验证 - pytest 发现所有新增测试类和测试函数 - 测试文件结构符合项目规范 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""共享测试 fixtures 和配置"""
|
||||
|
||||
import os
|
||||
from typing import Optional
|
||||
from unittest.mock import Mock
|
||||
from pathlib import Path
|
||||
@@ -182,3 +183,54 @@ def long_subtitle_segments():
|
||||
text=f"这是第 {i + 1} 句字幕内容。" * 5
|
||||
))
|
||||
return segments
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Phase 15 Fixtures: 配置集成测试
|
||||
# ============================================================================
|
||||
|
||||
@pytest.fixture
|
||||
def temp_env_vars(monkeypatch):
|
||||
"""临时环境变量 fixture,测试后自动清理"""
|
||||
original_env = {}
|
||||
saved_vars = {}
|
||||
|
||||
def _set_env(env_dict):
|
||||
nonlocal original_env, saved_vars
|
||||
# 保存原始值
|
||||
for key in env_dict.keys():
|
||||
original_env[key] = os.environ.get(key)
|
||||
# 设置新值
|
||||
for key, value in env_dict.items():
|
||||
if value is None:
|
||||
os.environ.pop(key, None)
|
||||
else:
|
||||
os.environ[key] = value
|
||||
saved_vars[key] = value
|
||||
|
||||
yield _set_env
|
||||
|
||||
# 清理:恢复原始环境变量
|
||||
for key, original_value in original_env.items():
|
||||
if original_value is None:
|
||||
os.environ.pop(key, None)
|
||||
else:
|
||||
os.environ[key] = original_value
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_kbsettings():
|
||||
"""Mock KBSettings fixture,用于隔离测试环境"""
|
||||
from kb_workflow.pipeline.config import KBSettings
|
||||
from kb_workflow.pipeline.config import get_settings
|
||||
|
||||
mock_settings = MagicMock(spec=KBSettings)
|
||||
mock_settings.enable_semantic_segmentation = True
|
||||
mock_settings.base_path = "/tmp/kb"
|
||||
mock_settings.archive_path = "/tmp/archive"
|
||||
mock_settings.hf_token = MagicMock()
|
||||
mock_settings.hf_token.get_secret_value.return_value = ""
|
||||
mock_settings.zhihu_cookie = MagicMock()
|
||||
mock_settings.zhihu_cookie.get_secret_value.return_value = ""
|
||||
|
||||
return mock_settings
|
||||
|
||||
Reference in New Issue
Block a user