Files

54 lines
1.6 KiB
Python

from tgbridge.formatter import build_caption, build_detail_messages, build_json_metadata
from tgbridge.metadata import GenerationMetadata, LoraEntry
def test_detail_message_omits_empty_sections_and_escapes_html():
metadata = GenerationMetadata(
positive_prompt="rain <neon>",
high_model="wan_high.safetensors",
low_model="wan_low.safetensors",
loras=(LoraEntry("detail.safetensors", 0.6),),
high_loras=("motion: 0.8",),
seed=42,
width=832,
height=480,
files=("out.mp4",),
)
messages = build_detail_messages(metadata)
text = messages[0]
assert "Prompt:\nrain &lt;neon&gt;" in text
assert "High: wan_high.safetensors" in text
assert "Low: wan_low.safetensors" in text
assert "- detail.safetensors: 0.6" in text
assert "High LoRA:\nmotion: 0.8" in text
assert "Size: 832x480" in text
assert "Negative:" not in text
def test_caption_prefers_title_and_settings():
metadata = GenerationMetadata(
title="Test clip",
positive_prompt="ignored prompt",
seed=123,
width=640,
height=360,
frames=72,
fps=12,
)
assert build_caption(metadata) == (
"Generation Complete\n\nTest clip\nSeed: 123\nSize: 640x360 | Frames: 72 | FPS: 12"
)
def test_json_metadata_contains_structured_fields():
metadata = GenerationMetadata(title="Clip", seed=1, files=("clip.mp4",))
content = build_json_metadata(metadata).decode("utf-8")
assert '"title": "Clip"' in content
assert '"seed": 1' in content
assert '"clip.mp4"' in content