Files
xiaoxia-saas/tests/unit/test_sticker_engine.py
T
CI Bot 7a72cfd709
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 / Validate - Migration (alembic) (push) Successful in 2m9s
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 2m19s
CI/CD Pipeline / Validate - Code Quality (push) Failing after 3m10s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 3m7s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 3m7s
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 1m17s
CI/CD Pipeline / Frontend Lint (push) Successful in 3m37s
CI/CD Pipeline / Integration Tests (push) Successful in 2m18s
CI/CD Pipeline / Unit Tests (push) Failing after 4m59s
CI/CD Pipeline / Build Staging API Image (push) Successful in 8m39s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 3m25s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 42s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 27m2s
CI/CD Pipeline / Staging API Integration Tests (push) Failing after 30m15s
style: auto-format with black + isort + prettier
2026-07-25 00:16:10 +00:00

123 lines
3.7 KiB
Python
Executable File

"""贴纸引擎单元测试 - 配置+解析等纯逻辑."""
from __future__ import annotations
import pytest
from video_processing.sticker_engine import (
ImageStickerConfig,
TextStickerConfig,
parse_stickers_from_config,
)
class TestImageStickerConfigDefaults:
"""ImageStickerConfig 默认值测试."""
def test_default_values(self):
"""默认值正确."""
s = ImageStickerConfig()
assert s.enabled is False
assert s.type == "image"
assert s.position == "top_right"
assert s.x is None
assert s.y is None
assert s.x_unit == "percent"
assert s.y_unit == "percent"
assert s.scale == 1.0
assert s.width is None
assert s.height is None
assert s.opacity == 1.0
assert s.start_time == 0.0
assert s.duration == 0.0
assert s.fade_in == 0.0
assert s.fade_out == 0.0
assert s.z_index == 10
assert s.image_url == ""
assert s.preset_id == ""
class TestTextStickerConfigDefaults:
"""TextStickerConfig 默认值测试."""
def test_default_values(self):
"""默认值正确."""
s = TextStickerConfig()
assert s.enabled is False
assert s.type == "text"
assert s.text == ""
assert s.font_size == 36
assert s.font_color == "#FFFFFF"
assert s.font_family == "sans"
assert s.stroke_color == "#000000"
assert s.stroke_width == 2
assert s.shadow_color == "#000000"
assert s.shadow_x == 2
assert s.shadow_y == 2
assert s.shadow_alpha == 0.5
assert s.position == "center"
assert s.start_time == 0.0
assert s.duration == 0.0
assert s.z_index == 10
assert s.bg_color == ""
assert s.bg_padding == 8
assert s.bg_alpha == 0.8
assert s.bg_corner_radius == 8
class TestParseStickersFromConfig:
"""parse_stickers_from_config 测试."""
def test_none_returns_empty(self):
"""None返回空列表."""
result = parse_stickers_from_config(None)
assert result == []
def test_empty_dict_returns_empty(self):
"""空dict返回空."""
result = parse_stickers_from_config({})
assert result == []
def test_no_stickers_key_returns_empty(self):
"""无stickers键返回空."""
result = parse_stickers_from_config({"other": "value"})
assert result == []
def test_stickers_not_list_returns_empty(self):
"""stickers不是列表返回空."""
result = parse_stickers_from_config({"stickers": "not_a_list"})
assert result == []
def test_empty_stickers_list(self):
"""空贴纸列表."""
result = parse_stickers_from_config({"stickers": []})
assert result == []
def test_single_sticker(self):
"""单个贴纸."""
result = parse_stickers_from_config(
{
"stickers": [{"type": "text", "text": "hello"}],
}
)
assert len(result) == 1
assert result[0]["text"] == "hello"
def test_multiple_stickers(self):
"""多个贴纸."""
result = parse_stickers_from_config(
{
"stickers": [
{"type": "text", "text": "a"},
{"type": "image", "image_url": "/b.png"},
{"type": "text", "text": "c"},
],
}
)
assert len(result) == 3
def test_returns_raw_dicts(self):
"""返回原始dict,不做转换."""
sticker = {"type": "text", "text": "test", "font_size": 48}
result = parse_stickers_from_config({"stickers": [sticker]})
assert result[0] is sticker # 引用相同,不做深拷贝