Files
xiaoxia-saas/tests/unit/test_ffmpeg_utils.py
CI Bot 3921a657e8
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Successful in 52s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 1m56s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 2m7s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 2m7s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 54s
CI/CD Pipeline / Validate - Code Quality (push) Failing after 3m20s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 6m27s
CI/CD Pipeline / Unit Tests (push) Failing after 8m24s
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Build Staging API Image (push) Successful in 16m1s
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m14s
CI/CD Pipeline / Integration Tests (push) Successful in 3m28s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 21s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 1m26s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m34s
style: auto-format with black + isort + prettier
2026-07-24 08:47:07 +00:00

81 lines
2.6 KiB
Python
Executable File

"""FFmpeg Utils 单元测试"""
from __future__ import annotations
import subprocess
import pytest
from packages.shared.ffmpeg_utils import (
DEFAULT_FFMPEG_TIMEOUT,
FFMPEG_BIN,
FFPROBE_BIN,
run_ffmpeg,
)
class TestFFmpegConstants:
"""常量测试"""
def test_ffmpeg_bin_is_string(self):
"""FFMPEG_BIN 是字符串"""
assert isinstance(FFMPEG_BIN, str)
assert len(FFMPEG_BIN) > 0
def test_ffprobe_bin_is_string(self):
"""FFPROBE_BIN 是字符串"""
assert isinstance(FFPROBE_BIN, str)
assert len(FFPROBE_BIN) > 0
def test_default_timeout_value(self):
"""默认超时 30 分钟"""
assert DEFAULT_FFMPEG_TIMEOUT == 1800
class TestRunFFmpeg:
"""run_ffmpeg 函数测试"""
def test_run_ffmpeg_version(self):
"""执行 ffmpeg -version 成功"""
stdout, stderr = run_ffmpeg([FFMPEG_BIN, "-version"])
# ffmpeg version 信息通常在 stdout 或 stderr 中
output = stdout + stderr
assert "ffmpeg" in output.lower() or "version" in output.lower()
def test_run_ffmpeg_capture_output_true(self):
"""capture_output=True 时返回字符串"""
stdout, stderr = run_ffmpeg([FFMPEG_BIN, "-version"])
assert isinstance(stdout, str)
assert isinstance(stderr, str)
def test_run_ffmpeg_invalid_command_raises(self):
"""无效命令抛出 CalledProcessError"""
with pytest.raises(subprocess.CalledProcessError):
run_ffmpeg([FFMPEG_BIN, "-invalid_flag_xyz"])
def test_run_ffmpeg_empty_command(self):
"""空命令列表抛出异常"""
with pytest.raises((FileNotFoundError, subprocess.CalledProcessError, IndexError)):
run_ffmpeg([])
def test_run_ffmpeg_custom_timeout(self):
"""自定义超时参数"""
# 用一个肯定不会超时的快速命令验证 timeout 参数能传入
stdout, stderr = run_ffmpeg([FFMPEG_BIN, "-version"], timeout=30)
assert isinstance(stdout, str)
def test_run_ffmpeg_timeout_expired(self):
"""超时触发 TimeoutExpired"""
# 用 sleep 模拟超时,但 ffmpeg 没有 sleep 功能
# 用一个会 hang 的命令(指定读取不存在的流)
# 实际上不好模拟,跳过具体超时测试,只验证类型
import subprocess as sp
assert hasattr(sp, "TimeoutExpired")
def test_run_ffmpeg_returns_tuple(self):
"""返回值是二元组"""
result = run_ffmpeg([FFMPEG_BIN, "-version"])
assert isinstance(result, tuple)
assert len(result) == 2