120 lines
3.6 KiB
Python
120 lines
3.6 KiB
Python
"""Unit tests for VideoConfig parsing and LoRASpec validation.
|
|
|
|
Pure-python, no model imports, no CUDA, no ffmpeg. Safe for Windows CI.
|
|
"""
|
|
import pytest
|
|
|
|
from server.video import VideoConfig, LoRASpec
|
|
|
|
|
|
def test_defaults_when_raw_is_empty():
|
|
cfg = VideoConfig.from_dict({})
|
|
assert cfg.enabled is False
|
|
assert cfg.backend == "lightx2v"
|
|
assert cfg.mode == "reflective"
|
|
assert cfg.resolution == 480
|
|
assert cfg.fps == 16
|
|
assert cfg.library_base_clip_count == 4
|
|
assert cfg.reflective_prompt_reply_words == 18
|
|
assert cfg.loras == []
|
|
|
|
|
|
def test_defaults_when_raw_is_none():
|
|
cfg = VideoConfig.from_dict(None) # type: ignore[arg-type]
|
|
assert cfg.enabled is False
|
|
|
|
|
|
def test_library_section_override():
|
|
cfg = VideoConfig.from_dict(
|
|
{"enabled": True, "mode": "library", "library": {"base_clip_count": 7, "base_clip_seconds": 3}}
|
|
)
|
|
assert cfg.enabled is True
|
|
assert cfg.mode == "library"
|
|
assert cfg.library_base_clip_count == 7
|
|
assert cfg.library_base_clip_seconds == 3
|
|
|
|
|
|
def test_reflective_section_override():
|
|
cfg = VideoConfig.from_dict(
|
|
{
|
|
"reflective": {
|
|
"clip_seconds": 9,
|
|
"clip_prompt_template": "my template: {reply_hint}",
|
|
"prompt_reply_words": 5,
|
|
}
|
|
}
|
|
)
|
|
assert cfg.reflective_clip_seconds == 9
|
|
assert cfg.reflective_prompt_template == "my template: {reply_hint}"
|
|
assert cfg.reflective_prompt_reply_words == 5
|
|
|
|
|
|
def test_lora_parse_minimal():
|
|
cfg = VideoConfig.from_dict({"loras": [{"path": "/tmp/a.safetensors"}]})
|
|
assert len(cfg.loras) == 1
|
|
lora = cfg.loras[0]
|
|
assert lora.path == "/tmp/a.safetensors"
|
|
assert lora.weight == 1.0
|
|
assert lora.target == "both"
|
|
assert lora.name is None
|
|
|
|
|
|
def test_lora_parse_full():
|
|
cfg = VideoConfig.from_dict(
|
|
{
|
|
"loras": [
|
|
{
|
|
"path": "/tmp/hi.safetensors",
|
|
"weight": 0.7,
|
|
"target": "high_noise",
|
|
"name": "hi-noise-style",
|
|
},
|
|
{
|
|
"path": "/tmp/lo.safetensors",
|
|
"weight": 0.4,
|
|
"target": "low_noise",
|
|
"name": "lo-noise-style",
|
|
},
|
|
]
|
|
}
|
|
)
|
|
assert len(cfg.loras) == 2
|
|
assert cfg.loras[0].target == "high_noise"
|
|
assert cfg.loras[0].name == "hi-noise-style"
|
|
assert cfg.loras[1].target == "low_noise"
|
|
assert cfg.loras[1].weight == 0.4
|
|
|
|
|
|
def test_lora_invalid_target_falls_back_to_both():
|
|
cfg = VideoConfig.from_dict(
|
|
{"loras": [{"path": "/tmp/x.safetensors", "target": "bogus"}]}
|
|
)
|
|
assert cfg.loras[0].target == "both"
|
|
|
|
|
|
def test_lora_entries_without_path_are_dropped():
|
|
cfg = VideoConfig.from_dict(
|
|
{"loras": [{"weight": 0.5}, {"path": "/tmp/ok.safetensors"}, None]}
|
|
)
|
|
assert len(cfg.loras) == 1
|
|
assert cfg.loras[0].path == "/tmp/ok.safetensors"
|
|
|
|
|
|
def test_models_section_override():
|
|
cfg = VideoConfig.from_dict(
|
|
{
|
|
"models": {
|
|
"wan22_base_repo": "/local/weights/wan22",
|
|
"wan22_fp8_repo": "/local/weights/wan22-fp8",
|
|
"wan22_config_json": "/local/cfg/fp8.json",
|
|
"wan22_model_cls": "wan2.2_moe",
|
|
"musetalk_path": "/local/weights/musetalk",
|
|
}
|
|
}
|
|
)
|
|
assert cfg.wan22_base_repo == "/local/weights/wan22"
|
|
assert cfg.wan22_fp8_repo == "/local/weights/wan22-fp8"
|
|
assert cfg.wan22_config_json == "/local/cfg/fp8.json"
|
|
assert cfg.wan22_model_cls == "wan2.2_moe"
|
|
assert cfg.musetalk_model_path == "/local/weights/musetalk"
|