d66046aa4b
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
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 / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Build Staging Web Image (push) Successful in 57s
CI/CD Pipeline / Build Staging API Image (push) Successful in 1m30s
CI/CD Pipeline / Frontend Lint (push) Successful in 1m41s
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
205 lines
6.5 KiB
Python
Executable File
205 lines
6.5 KiB
Python
Executable File
"""TTS 配音配置领域模型单元测试."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from packages.domain.tts_config import TtsConfig
|
|
|
|
|
|
class TestTtsConfigDefaults:
|
|
"""默认值测试."""
|
|
|
|
def test_default_values(self):
|
|
config = TtsConfig()
|
|
assert config.enabled is False
|
|
assert config.voice_id == ""
|
|
assert config.speed == 1.0
|
|
assert config.pitch == 0.0
|
|
assert config.volume == 0.8
|
|
assert config.text == ""
|
|
assert config.align_mode == "full"
|
|
assert config.overlap_mode == "replace"
|
|
|
|
|
|
class TestTtsConfigParse:
|
|
"""parse 方法测试."""
|
|
|
|
def test_parse_none_returns_default(self):
|
|
config = TtsConfig.parse(None)
|
|
assert config.enabled is False
|
|
|
|
def test_parse_empty_dict_returns_default(self):
|
|
config = TtsConfig.parse({})
|
|
assert config.enabled is False
|
|
|
|
def test_parse_not_dict_returns_default(self):
|
|
config = TtsConfig.parse("invalid")
|
|
assert config.enabled is False
|
|
config2 = TtsConfig.parse(123)
|
|
assert config2.enabled is False
|
|
config3 = TtsConfig.parse([])
|
|
assert config3.enabled is False
|
|
|
|
def test_parse_enabled_false_ignores_other_fields(self):
|
|
data = {
|
|
"enabled": False,
|
|
"voice_id": "test_voice",
|
|
"speed": 2.0,
|
|
"text": "hello",
|
|
}
|
|
config = TtsConfig.parse(data)
|
|
assert config.enabled is False
|
|
assert config.voice_id == ""
|
|
assert config.speed == 1.0
|
|
|
|
def test_parse_basic_enabled(self):
|
|
data = {"enabled": True, "voice_id": "voice_001"}
|
|
config = TtsConfig.parse(data)
|
|
assert config.enabled is True
|
|
assert config.voice_id == "voice_001"
|
|
assert config.speed == 1.0
|
|
assert config.pitch == 0.0
|
|
assert config.volume == 0.8
|
|
|
|
def test_parse_full_config(self):
|
|
data = {
|
|
"enabled": True,
|
|
"voice_id": "voice_001",
|
|
"speed": 1.5,
|
|
"pitch": 2.0,
|
|
"volume": 0.9,
|
|
"text": "测试配音文本",
|
|
"align_mode": "subtitle",
|
|
"overlap_mode": "mix",
|
|
}
|
|
config = TtsConfig.parse(data)
|
|
assert config.enabled is True
|
|
assert config.voice_id == "voice_001"
|
|
assert config.speed == 1.5
|
|
assert config.pitch == 2.0
|
|
assert config.volume == 0.9
|
|
assert config.text == "测试配音文本"
|
|
assert config.align_mode == "subtitle"
|
|
assert config.overlap_mode == "mix"
|
|
|
|
def test_parse_enabled_non_bool_fallback(self):
|
|
data = {"enabled": "true", "voice_id": "v1"}
|
|
config = TtsConfig.parse(data)
|
|
assert config.enabled is False
|
|
|
|
def test_parse_voice_id_non_string_fallback(self):
|
|
data = {"enabled": True, "voice_id": 123}
|
|
config = TtsConfig.parse(data)
|
|
assert config.voice_id == ""
|
|
|
|
def test_parse_speed_non_numeric_fallback(self):
|
|
data = {"enabled": True, "speed": "fast"}
|
|
config = TtsConfig.parse(data)
|
|
assert config.speed == 1.0
|
|
|
|
def test_parse_pitch_non_numeric_fallback(self):
|
|
data = {"enabled": True, "pitch": "high"}
|
|
config = TtsConfig.parse(data)
|
|
assert config.pitch == 0.0
|
|
|
|
def test_parse_volume_non_numeric_fallback(self):
|
|
data = {"enabled": True, "volume": "loud"}
|
|
config = TtsConfig.parse(data)
|
|
assert config.volume == 0.8
|
|
|
|
def test_parse_text_non_string_fallback(self):
|
|
data = {"enabled": True, "text": 12345}
|
|
config = TtsConfig.parse(data)
|
|
assert config.text == ""
|
|
|
|
def test_parse_align_mode_invalid_fallback(self):
|
|
data = {"enabled": True, "align_mode": "invalid"}
|
|
config = TtsConfig.parse(data)
|
|
assert config.align_mode == "full"
|
|
|
|
def test_parse_overlap_mode_invalid_fallback(self):
|
|
data = {"enabled": True, "overlap_mode": "invalid"}
|
|
config = TtsConfig.parse(data)
|
|
assert config.overlap_mode == "replace"
|
|
|
|
|
|
class TestTtsConfigClamp:
|
|
"""边界钳制测试."""
|
|
|
|
def test_speed_below_min_clamped(self):
|
|
data = {"enabled": True, "speed": 0.1}
|
|
config = TtsConfig.parse(data)
|
|
assert config.speed == 0.5
|
|
|
|
def test_speed_above_max_clamped(self):
|
|
data = {"enabled": True, "speed": 3.0}
|
|
config = TtsConfig.parse(data)
|
|
assert config.speed == 2.0
|
|
|
|
def test_speed_at_min_ok(self):
|
|
data = {"enabled": True, "speed": 0.5}
|
|
config = TtsConfig.parse(data)
|
|
assert config.speed == 0.5
|
|
|
|
def test_speed_at_max_ok(self):
|
|
data = {"enabled": True, "speed": 2.0}
|
|
config = TtsConfig.parse(data)
|
|
assert config.speed == 2.0
|
|
|
|
def test_pitch_below_min_clamped(self):
|
|
data = {"enabled": True, "pitch": -20}
|
|
config = TtsConfig.parse(data)
|
|
assert config.pitch == -12
|
|
|
|
def test_pitch_above_max_clamped(self):
|
|
data = {"enabled": True, "pitch": 20}
|
|
config = TtsConfig.parse(data)
|
|
assert config.pitch == 12
|
|
|
|
def test_pitch_at_min_ok(self):
|
|
data = {"enabled": True, "pitch": -12}
|
|
config = TtsConfig.parse(data)
|
|
assert config.pitch == -12
|
|
|
|
def test_pitch_at_max_ok(self):
|
|
data = {"enabled": True, "pitch": 12}
|
|
config = TtsConfig.parse(data)
|
|
assert config.pitch == 12
|
|
|
|
def test_volume_below_min_clamped(self):
|
|
data = {"enabled": True, "volume": -0.5}
|
|
config = TtsConfig.parse(data)
|
|
assert config.volume == 0.0
|
|
|
|
def test_volume_above_max_clamped(self):
|
|
data = {"enabled": True, "volume": 2.0}
|
|
config = TtsConfig.parse(data)
|
|
assert config.volume == 1.0
|
|
|
|
def test_volume_at_min_ok(self):
|
|
data = {"enabled": True, "volume": 0.0}
|
|
config = TtsConfig.parse(data)
|
|
assert config.volume == 0.0
|
|
|
|
def test_volume_at_max_ok(self):
|
|
data = {"enabled": True, "volume": 1.0}
|
|
config = TtsConfig.parse(data)
|
|
assert config.volume == 1.0
|
|
|
|
def test_int_speed_converted_to_float(self):
|
|
data = {"enabled": True, "speed": 1}
|
|
config = TtsConfig.parse(data)
|
|
assert isinstance(config.speed, float)
|
|
assert config.speed == 1.0
|
|
|
|
def test_int_pitch_converted_to_float(self):
|
|
data = {"enabled": True, "pitch": 5}
|
|
config = TtsConfig.parse(data)
|
|
assert isinstance(config.pitch, float)
|
|
assert config.pitch == 5.0
|
|
|
|
def test_int_volume_converted_to_float(self):
|
|
data = {"enabled": True, "volume": 1}
|
|
config = TtsConfig.parse(data)
|
|
assert isinstance(config.volume, float)
|
|
assert config.volume == 1.0
|