You've already forked FrameTour-RenderWorker
test(handlers): 添加基础处理器并行传输相关单元测试
- 实现 download_files_parallel 方法的并发下载功能测试 - 验证上传文件并行处理收集URL功能的正确性 - 测试下载文件时设置锁等待时间跨度属性 - 验证无缓存下载时锁等待时间为零的场景 - 测试上传文件时设置详细的跨度属性功能 - 添加渲染视频效果相关的参数解析测试 - 实现存储服务上传指标
This commit is contained in:
84
tests/unit/test_render_video_effects.py
Normal file
84
tests/unit/test_render_video_effects.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytest
|
||||
|
||||
from domain.config import WorkerConfig
|
||||
from domain.task import Effect, OutputSpec, RenderSpec
|
||||
from handlers.render_video import RenderSegmentVideoHandler
|
||||
|
||||
|
||||
class _DummyApiClient:
|
||||
pass
|
||||
|
||||
|
||||
def _create_handler(tmp_path):
|
||||
config = WorkerConfig(
|
||||
api_endpoint='http://127.0.0.1:18084/api',
|
||||
access_key='TEST_ACCESS_KEY',
|
||||
worker_id='test-worker',
|
||||
temp_dir=str(tmp_path),
|
||||
cache_enabled=False,
|
||||
cache_dir=str(tmp_path / 'cache')
|
||||
)
|
||||
return RenderSegmentVideoHandler(config, _DummyApiClient())
|
||||
|
||||
|
||||
def test_get_zoom_params_with_valid_values():
|
||||
effect = Effect.from_string('zoom:1.5,1.35,2')
|
||||
assert effect is not None
|
||||
|
||||
start_sec, scale_factor, duration_sec = effect.get_zoom_params()
|
||||
assert start_sec == pytest.approx(1.5)
|
||||
assert scale_factor == pytest.approx(1.35)
|
||||
assert duration_sec == pytest.approx(2.0)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'effect_str',
|
||||
[
|
||||
'zoom:-1,0.9,-2',
|
||||
'zoom:nan,inf,0',
|
||||
'zoom:bad,value,data',
|
||||
'zoom:,,',
|
||||
],
|
||||
)
|
||||
def test_get_zoom_params_invalid_values_fallback_to_default(effect_str):
|
||||
effect = Effect.from_string(effect_str)
|
||||
assert effect is not None
|
||||
assert effect.get_zoom_params() == (0.0, 1.2, 1.0)
|
||||
|
||||
|
||||
def test_build_command_with_zoom_uses_filter_complex(tmp_path):
|
||||
handler = _create_handler(tmp_path)
|
||||
render_spec = RenderSpec(effects='zoom:1.5,1.4,2')
|
||||
output_spec = OutputSpec(width=1080, height=1920, fps=30)
|
||||
|
||||
command = handler._build_command(
|
||||
input_file='input.mp4',
|
||||
output_file='output.mp4',
|
||||
render_spec=render_spec,
|
||||
output_spec=output_spec,
|
||||
duration_ms=6000,
|
||||
)
|
||||
|
||||
assert '-filter_complex' in command
|
||||
assert '-vf' not in command
|
||||
|
||||
|
||||
def test_build_video_filters_zoom_and_camera_shot_stack_in_order(tmp_path):
|
||||
handler = _create_handler(tmp_path)
|
||||
render_spec = RenderSpec(effects='cameraShot:3,1|zoom:1,1.2,2')
|
||||
output_spec = OutputSpec(width=1080, height=1920, fps=30)
|
||||
|
||||
filters = handler._build_video_filters(
|
||||
render_spec=render_spec,
|
||||
output_spec=output_spec,
|
||||
duration_ms=8000,
|
||||
source_duration_sec=10.0,
|
||||
)
|
||||
|
||||
camera_shot_marker = 'concat=n=2:v=1:a=0'
|
||||
zoom_marker = "overlay=0:0:enable='between(t,1.0,3.0)'"
|
||||
assert camera_shot_marker in filters
|
||||
assert zoom_marker in filters
|
||||
assert filters.index(camera_shot_marker) < filters.index(zoom_marker)
|
||||
Reference in New Issue
Block a user