Files
JeyzerMC-comfyui-flakes/tests/test_caption_instructions.py

35 lines
1.1 KiB
Python

"""Tests for the built-in auto-caption instructions (#482)."""
import importlib.util
import os
from types import SimpleNamespace
import pytest
_src = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "flake_caption.py")
_spec = importlib.util.spec_from_file_location("flake_caption", _src)
cap = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(cap)
def _preset(family, caption_instruction=""):
return SimpleNamespace(family=family, caption_instruction=caption_instruction)
@pytest.mark.parametrize("family", ["mh3", "wan22"])
def test_family_default(family):
assert cap.instruction_for(_preset(family)) == cap.INSTRUCTIONS[family]
assert cap.INSTRUCTIONS[family].strip()
def test_override_wins_and_is_stripped():
assert cap.instruction_for(_preset("mh3", " custom\n")) == "custom"
def test_blank_override_falls_back():
assert cap.instruction_for(_preset("wan22", " ")) == cap.INSTRUCTIONS["wan22"]
def test_unknown_family_errors():
with pytest.raises(ValueError, match="other"):
cap.instruction_for(_preset("other"))