Files
xiaoxia-saas/tests/unit/test_thumbnail_generator.py
T
CI Bot 032c07fdc3
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 44s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m45s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m8s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 31s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m32s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 48s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m46s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 28s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 59s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 4m32s
AI Code Review / AI Code Review (pull_request) Successful in 4m18s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m48s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m41s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 3m5s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m7s
test(unit): 第63波 - watermark + noise_reduction + thumbnail 纯逻辑
- test_watermark_engine: 水印引擎,56个用例
  - WatermarkConfig.from_dict (16个) + validate (17个)
  - WatermarkEngine.calc_position 9宫格 + 边界 (14个)
  - calc_scroll_x + 位置常量 (5个)

- test_noise_reduction_engine: 降噪引擎,20个用例
  - NoiseReductionLevel 枚举
  - NoiseReductionConfig.from_dict 解析 + 边界钳制
  - has_effect + get_effective_noise_floor

- test_thumbnail_generator: 缩略图生成,13个用例
  - _format_seek_time 时间格式化
  - 零值/分/时/长视频/精度校验

+89
2026-07-25 00:11:23 +08:00

90 lines
2.6 KiB
Python
Executable File

"""缩略图生成器单元测试 - 纯逻辑函数."""
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 # 两位小数