"""缩略图生成器单元测试 - 纯逻辑函数.""" from __future__ import annotations import pytest from video_processing.thumbnail_generator import _format_seek_time class TestFormatSeekTime: """_format_seek_time 时间格式化测试.""" def test_zero_seconds(self): """0秒.""" result = _format_seek_time(0) assert result == "00:00:00.00" def test_less_than_one_second(self): """小于1秒.""" result = _format_seek_time(0.5) assert result == "00:00:00.50" def test_few_seconds(self): """几秒.""" result = _format_seek_time(5.5) assert result == "00:00:05.50" def test_one_minute(self): """1分钟.""" result = _format_seek_time(60.0) assert result == "00:01:00.00" def test_minutes_and_seconds(self): """分+秒.""" result = _format_seek_time(125.5) assert result == "00:02:05.50" def test_one_hour(self): """1小时.""" result = _format_seek_time(3600.0) assert result == "01:00:00.00" def test_hours_minutes_seconds(self): """时+分+秒.""" result = _format_seek_time(3725.25) assert result == "01:02:05.25" def test_long_duration(self): """长视频(2小时以上).""" result = _format_seek_time(7384.12) assert result == "02:03:04.12" def test_precision_two_decimal(self): """两位小数精度.""" result = _format_seek_time(3.14159) assert result == "00:00:03.14" def test_always_two_digit_hours(self): """小时始终两位数字.""" result = _format_seek_time(3600 * 9) assert result.startswith("09:") def test_always_two_digit_minutes(self): """分钟始终两位数字.""" result = _format_seek_time(300) # 5分钟 parts = result.split(":") assert parts[1] == "05" def test_float_input(self): """浮点数输入.""" result = _format_seek_time(10.0) assert isinstance(result, str) assert result == "00:00:10.00" def test_int_input(self): """整数输入.""" result = _format_seek_time(30) assert result == "00:00:30.00" def test_format_structure(self): """格式结构正确:HH:MM:SS.xx.""" result = _format_seek_time(3661.5) # 格式: HH:MM:SS.xx parts = result.split(":") assert len(parts) == 3 assert "." in parts[2] sec_parts = parts[2].split(".") assert len(sec_parts) == 2 assert len(sec_parts[1]) == 2 # 两位小数