64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from ComfyUI_H3_Continuum_Join.prompt_builder import (
|
|
DumasH3SequencePromptBuilder,
|
|
default_sequence,
|
|
format_sequence_prompt,
|
|
normalize_sequence,
|
|
)
|
|
|
|
|
|
def test_builder_emits_one_absolute_timeline_prompt_from_clip_local_slots():
|
|
sequence = normalize_sequence(
|
|
{"clips": [
|
|
{"duration": 4, "slots": [{"start": 0, "end": 2, "text": "Walk forward."}]},
|
|
{"duration": 5, "slots": [{"start": 1, "end": 5, "text": "Turn toward the light."}]},
|
|
]},
|
|
clip_count=2,
|
|
default_seconds=4,
|
|
)
|
|
result = format_sequence_prompt(
|
|
shared_directive="Preserve the same character and environment.",
|
|
sequence=sequence,
|
|
soundscape="Quiet street ambience.",
|
|
music="Low cinematic pulse.",
|
|
)
|
|
assert "[0-2s]" in result
|
|
assert "[5-9s]" in result
|
|
assert "overall_soundscape: Quiet street ambience." in result
|
|
assert "non_diegetic_music: Low cinematic pulse." in result
|
|
|
|
|
|
def test_normalizer_orders_slots_and_fills_missing_clips():
|
|
value = normalize_sequence(
|
|
json.dumps({"clips": [{"duration": 6, "slots": [
|
|
{"start": 3, "end": 6, "text": "Second."},
|
|
{"start": 0, "end": 3, "text": "First."},
|
|
]}]}),
|
|
clip_count=2,
|
|
default_seconds=4,
|
|
)
|
|
assert value["clips"][0]["slots"][0]["text"] == "First."
|
|
assert value["clips"][1]["duration"] == 4.0
|
|
|
|
|
|
@pytest.mark.parametrize("bad", [
|
|
{"clips": [{"duration": 4, "slots": [{"start": 3, "end": 2, "text": "bad"}]}]},
|
|
{"clips": [{"duration": 4, "slots": [{"start": 0, "end": 5, "text": "bad"}]}]},
|
|
])
|
|
def test_normalizer_rejects_invalid_slot_ranges(bad):
|
|
with pytest.raises(ValueError):
|
|
normalize_sequence(bad, clip_count=1, default_seconds=4)
|
|
|
|
|
|
def test_node_schema_has_single_string_output_and_serialized_editor_state():
|
|
schema = DumasH3SequencePromptBuilder.INPUT_TYPES()["required"]
|
|
assert DumasH3SequencePromptBuilder.RETURN_TYPES == ("STRING",)
|
|
assert schema["timeline_json"][1]["multiline"] is True
|
|
result = DumasH3SequencePromptBuilder().build(1, 4, "Directive", json.dumps(default_sequence(1, 4)), "N/A", "N/A")
|
|
assert result[0].startswith("Directive\n\noverall_soundscape:")
|