b2330c32c8
- Add ASRInput schema with video_path and content_type fields - Add ASROutput schema with tool/has_subtitle/output_files/segments/text/duration_seconds/speakers - Create test_processors directory with conftest fixtures - Add comprehensive schema tests (8 test cases) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
97 lines
2.3 KiB
Python
97 lines
2.3 KiB
Python
"""Shared fixtures for processor tests"""
|
|
|
|
import os
|
|
import pytest
|
|
from pathlib import Path
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_whisper_path(tmp_path):
|
|
"""Mock whisper.cpp path"""
|
|
whisper_dir = tmp_path / "whisper.cpp"
|
|
whisper_dir.mkdir()
|
|
(whisper_dir / "whisper-cli").write_text("")
|
|
models_dir = whisper_dir / "models"
|
|
models_dir.mkdir()
|
|
(models_dir / "ggml-base.bin").write_text("")
|
|
return str(whisper_dir)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_bilibili_api():
|
|
"""Mock B站 API 响应"""
|
|
with patch("aiohttp.ClientSession.get") as mock_get:
|
|
yield mock_get
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_video(tmp_path):
|
|
"""创建测试视频文件"""
|
|
video_path = tmp_path / "test_video.mp4"
|
|
video_path.write_text("fake video content")
|
|
return str(video_path)
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_subtitle_response():
|
|
"""B站字幕 API 响应示例"""
|
|
return {
|
|
"data": {
|
|
"subtitle": {
|
|
"list": [{
|
|
"lan": "ai-zh",
|
|
"lan_doc": "中文(自动生成)",
|
|
"subtitle_url": "//example.com/subtitle.json"
|
|
}]
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_subtitle_content():
|
|
"""字幕内容示例"""
|
|
return {
|
|
"body": [
|
|
{"from": 0.0, "to": 3.2, "content": "这是第一段字幕"},
|
|
{"from": 3.5, "to": 6.8, "content": "这是第二段字幕"},
|
|
]
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_whisper_output(tmp_path):
|
|
"""Whisper 输出示例"""
|
|
output_base = tmp_path / "test_video"
|
|
return {
|
|
"txt": str(output_base.with_suffix(".txt")),
|
|
"srt": str(output_base.with_suffix(".srt")),
|
|
"json": str(output_base.with_suffix(".json")),
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_state_manager():
|
|
"""Mock WorkflowStateManager"""
|
|
manager = MagicMock()
|
|
manager.load.return_value = None
|
|
manager.save = MagicMock()
|
|
return manager
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_settings():
|
|
"""Mock KBSettings without HF_TOKEN"""
|
|
settings = MagicMock()
|
|
settings.hf_token.get_secret_value.return_value = ""
|
|
return settings
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_settings_with_hf_token():
|
|
"""Mock KBSettings with HF_TOKEN"""
|
|
settings = MagicMock()
|
|
settings.hf_token.get_secret_value.return_value = "test_hf_token_123"
|
|
return settings
|