video-processor/tests/unit/test_ffmpeg_utils.py
Ryan Malloy 90508c417d Implement comprehensive test video suite with fixtures and integration
- Created comprehensive test video downloader (CC-licensed content)
- Built synthetic video generator for edge cases, codecs, patterns
- Added test suite manager with categorized test suites (smoke, basic, codecs, edge_cases, stress)
- Generated 108+ test videos covering various scenarios
- Updated integration tests to use comprehensive test suite
- Added comprehensive video processing integration tests
- Validated test suite structure and accessibility

Test Results:
- Generated 99 valid test videos (9 invalid by design)
- Successfully created edge cases: single frame, unusual resolutions, high FPS
- Multiple codec support: H.264, H.265, VP8, VP9, Theora, MPEG4
- Audio variations: mono/stereo, different sample rates, no audio, audio-only
- Visual patterns: SMPTE bars, RGB test, YUV test, checkerboard
- Motion tests: rotation, camera shake, scene changes
- Stress tests: high complexity scenes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-05 12:32:20 -06:00

148 lines
5.2 KiB
Python

"""Test FFmpeg utilities."""
import subprocess
from pathlib import Path
from unittest.mock import Mock, patch
import pytest
from video_processor.utils.ffmpeg import FFmpegUtils
from video_processor.exceptions import FFmpegError
class TestFFmpegUtils:
"""Test FFmpeg utility functions."""
def test_ffmpeg_detection(self):
"""Test FFmpeg binary detection."""
# Test with default path
available = FFmpegUtils.check_ffmpeg_available()
if not available:
pytest.skip("FFmpeg not available on system")
assert available is True
@patch('subprocess.run')
def test_ffmpeg_not_found(self, mock_run):
"""Test handling when FFmpeg is not found."""
mock_run.side_effect = FileNotFoundError()
available = FFmpegUtils.check_ffmpeg_available("/nonexistent/ffmpeg")
assert available is False
@patch('subprocess.run')
def test_ffmpeg_timeout(self, mock_run):
"""Test FFmpeg timeout handling."""
mock_run.side_effect = subprocess.TimeoutExpired(
cmd=["ffmpeg"], timeout=10
)
available = FFmpegUtils.check_ffmpeg_available()
assert available is False
@patch('subprocess.run')
def test_get_ffmpeg_version(self, mock_run):
"""Test getting FFmpeg version."""
mock_run.return_value = Mock(
returncode=0,
stdout="ffmpeg version 4.4.2-0ubuntu0.22.04.1"
)
version = FFmpegUtils.get_ffmpeg_version()
assert version == "4.4.2-0ubuntu0.22.04.1"
@patch('subprocess.run')
def test_get_ffmpeg_version_failure(self, mock_run):
"""Test getting FFmpeg version when it fails."""
mock_run.return_value = Mock(returncode=1)
version = FFmpegUtils.get_ffmpeg_version()
assert version is None
def test_validate_input_file_exists(self, valid_video):
"""Test validating existing input file."""
# This should not raise an exception
try:
FFmpegUtils.validate_input_file(valid_video)
except FFmpegError:
pytest.skip("ffmpeg-python not available for file validation")
def test_validate_input_file_missing(self, temp_dir):
"""Test validating missing input file."""
missing_file = temp_dir / "missing.mp4"
with pytest.raises(FFmpegError) as exc_info:
FFmpegUtils.validate_input_file(missing_file)
assert "does not exist" in str(exc_info.value)
def test_validate_input_file_directory(self, temp_dir):
"""Test validating directory instead of file."""
with pytest.raises(FFmpegError) as exc_info:
FFmpegUtils.validate_input_file(temp_dir)
assert "not a file" in str(exc_info.value)
def test_estimate_processing_time_basic(self, temp_dir):
"""Test basic processing time estimation."""
# Create a dummy file for testing
dummy_file = temp_dir / "dummy.mp4"
dummy_file.touch()
try:
estimate = FFmpegUtils.estimate_processing_time(
input_file=dummy_file,
output_formats=["mp4"],
quality_preset="medium"
)
# Should return at least the minimum time
assert estimate >= 60
except Exception:
# If ffmpeg-python not available, skip
pytest.skip("ffmpeg-python not available for estimation")
@pytest.mark.parametrize("quality_preset", ["low", "medium", "high", "ultra"])
def test_estimate_processing_time_quality_presets(self, quality_preset, temp_dir):
"""Test processing time estimates for different quality presets."""
dummy_file = temp_dir / "dummy.mp4"
dummy_file.touch()
try:
estimate = FFmpegUtils.estimate_processing_time(
input_file=dummy_file,
output_formats=["mp4"],
quality_preset=quality_preset
)
assert estimate >= 60
except Exception:
pytest.skip("ffmpeg-python not available for estimation")
@pytest.mark.parametrize("formats", [
["mp4"],
["mp4", "webm"],
["mp4", "webm", "ogv"],
])
def test_estimate_processing_time_formats(self, formats, temp_dir):
"""Test processing time estimates for different format combinations."""
dummy_file = temp_dir / "dummy.mp4"
dummy_file.touch()
try:
estimate = FFmpegUtils.estimate_processing_time(
input_file=dummy_file,
output_formats=formats,
quality_preset="medium"
)
assert estimate >= 60
# More formats should take longer
if len(formats) > 1:
single_format_estimate = FFmpegUtils.estimate_processing_time(
input_file=dummy_file,
output_formats=formats[:1],
quality_preset="medium"
)
assert estimate >= single_format_estimate
except Exception:
pytest.skip("ffmpeg-python not available for estimation")