9862da7085
- 创建 conftest.py 共享 fixtures(MockAIClient, sample_segments) - 创建 test_semantic_engine.py 包含 8 个测试用例 - test_video_type_detection_from_title: 测试从标题推断类型 - test_video_type_detection_from_category: 测试从分类推断类型 - test_video_type_fallback_to_default: 测试默认类型回退 - test_video_type_in_prompt: 测试类型出现在 Prompt 中 - test_prompt_format: 测试 Prompt 格式 - test_video_segment_model: 测试 VideoSegment 模型 - test_segmentation_result_model: 测试 SegmentationResult 模型 - test_model_validation: 测试字段验证 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
"""共享测试 fixtures 和配置"""
|
|
|
|
from typing import Optional
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
|
|
class MockAIClient:
|
|
"""模拟 AI 客户端"""
|
|
|
|
def __init__(self, response: str = "Mock AI response"):
|
|
self.response = response
|
|
|
|
def generate(
|
|
self,
|
|
prompt: str,
|
|
max_tokens: int = 16000,
|
|
disable_reasoning: Optional[bool] = None
|
|
) -> str:
|
|
"""生成模拟响应"""
|
|
return self.response
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_ai_client():
|
|
"""提供模拟 AI 客户端"""
|
|
return MockAIClient()
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_segments():
|
|
"""提供示例字幕分段数据"""
|
|
return [
|
|
{"index": 1, "start": "00:00:00,000", "end": "00:00:05,000", "text": "大家好,欢迎来到我的频道"},
|
|
{"index": 2, "start": "00:00:05,000", "end": "00:00:10,000", "text": "今天我们要讲的是机器学习的基础知识"},
|
|
{"index": 3, "start": "00:00:10,000", "end": "00:00:15,000", "text": "首先,什么是机器学习"},
|
|
{"index": 4, "start": "00:00:15,000", "end": "00:00:20,000", "text": "机器学习是人工智能的一个分支"},
|
|
{"index": 5, "start": "00:00:20,000", "end": "00:00:25,000", "text": "它让计算机能够从数据中学习"},
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_metadata():
|
|
"""提供示例视频元数据"""
|
|
return {
|
|
"title": "机器学习入门教程",
|
|
"category": "教育",
|
|
"tags": ["编程", "AI", "教程"],
|
|
"description": "从零开始学习机器学习"
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_metadata_movie():
|
|
"""提供电影类型示例元数据"""
|
|
return {
|
|
"title": "星际穿越",
|
|
"category": "影视",
|
|
"tags": ["科幻", "电影"],
|
|
"description": "一部关于太空探索的科幻电影"
|
|
}
|