Files

63 lines
1.8 KiB
Python

import pytest
from tgbridge.metadata import build_metadata, resolve_send_type, select_files
def test_select_files_final_only_uses_last_existing_file(tmp_path):
first = tmp_path / "metadata.png"
second = tmp_path / "video.mp4"
first.write_bytes(b"png")
second.write_bytes(b"mp4")
selected, missing = select_files([str(first), str(tmp_path / "missing.mp4"), str(second)], "final_only")
assert selected == [str(second)]
assert missing == [str(tmp_path / "missing.mp4")]
def test_select_files_all_files_returns_existing_files(tmp_path):
first = tmp_path / "a.mp4"
second = tmp_path / "b.mp4"
first.write_bytes(b"a")
second.write_bytes(b"b")
selected, missing = select_files([str(first), str(second)], "all_files")
assert selected == [str(first), str(second)]
assert missing == []
@pytest.mark.parametrize(
("path", "expected"),
[
("clip.mp4", "video"),
("clip.webm", "video"),
("image.png", "photo"),
("workflow.json", "document"),
],
)
def test_resolve_send_type_auto(path, expected):
assert resolve_send_type(path, "auto") == expected
def test_build_metadata_omits_sentinel_values_and_collects_loras(tmp_path):
file_path = tmp_path / "out.mp4"
metadata = build_metadata(
{
"seed": -1,
"steps": 30,
"cfg": 0.0,
"lora_1_name": "motion.safetensors",
"lora_1_strength": 0.75,
"high_loras": "high_a: 0.5\n\nhigh_b: 0.8",
},
[str(file_path)],
)
assert metadata.seed is None
assert metadata.steps == 30
assert metadata.cfg is None
assert metadata.loras[0].as_text() == "motion.safetensors: 0.75"
assert metadata.high_loras == ("high_a: 0.5", "high_b: 0.8")
assert metadata.files == ("out.mp4",)