Replace H3 nodes with generic sequential video tools
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
import importlib
|
||||
import unittest
|
||||
|
||||
|
||||
class DumasH3BeatPromptTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.module = importlib.import_module("dumas_h3_beat_prompt")
|
||||
|
||||
def test_parse_state_falls_back_to_default(self):
|
||||
state = self.module._parse_beat_prompt_state("not json")
|
||||
self.assertEqual(
|
||||
state,
|
||||
{
|
||||
"scene": "",
|
||||
"character_sheet": "",
|
||||
"beats": [{"text": "Describe this beat."}],
|
||||
},
|
||||
)
|
||||
|
||||
def test_assemble_prompt_outputs_upstream_sections(self):
|
||||
prompt = self.module._assemble_beat_prompt(
|
||||
{
|
||||
"scene": "A rainy kitchen at night.",
|
||||
"character_sheet": "Maya: 27, she, red jacket, silver hair.",
|
||||
"beats": [
|
||||
{"text": "Maya enters the room."},
|
||||
{"text": "remove: red jacket\nadd: white shirt underneath\nShe sits at the table."},
|
||||
{"text": " "},
|
||||
]
|
||||
}
|
||||
)
|
||||
self.assertEqual(
|
||||
prompt,
|
||||
(
|
||||
"A rainy kitchen at night.\n\n"
|
||||
"Maya: 27, she, red jacket, silver hair.\n\n"
|
||||
"Maya enters the room.\n\n"
|
||||
"remove: red jacket\nadd: white shirt underneath\nShe sits at the table."
|
||||
),
|
||||
)
|
||||
|
||||
def test_assemble_prompt_strips_old_dumas_directives(self):
|
||||
prompt = self.module._assemble_beat_prompt(
|
||||
{
|
||||
"beats": [
|
||||
{
|
||||
"text": (
|
||||
"seconds: 8\n"
|
||||
"continuity: hard cut\n"
|
||||
"ref_mode: every shot\n"
|
||||
"soundscape: soft rain\n"
|
||||
"music: low synth\n"
|
||||
"Maya opens the cupboard.\n"
|
||||
"remove: red jacket"
|
||||
)
|
||||
},
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(prompt, "Maya opens the cupboard.\nremove: red jacket")
|
||||
|
||||
def test_node_build_prompt_uses_hidden_state(self):
|
||||
node = self.module.DumasH3BeatPromptNode()
|
||||
result = node.build_prompt(
|
||||
'{"scene":"Scene","character_sheet":"Maya: 27, she","beats":[{"text":"Beat one"},{"text":"Beat two"}]}'
|
||||
)
|
||||
self.assertEqual(result, ("Scene\n\nMaya: 27, she\n\nBeat one\n\nBeat two",))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,149 +0,0 @@
|
||||
import importlib
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
|
||||
|
||||
class DumasH3LongVideosUpstreamWrapperTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls._saved_modules = {
|
||||
name: sys.modules.get(name)
|
||||
for name in (
|
||||
"torch",
|
||||
"nodes",
|
||||
"comfy",
|
||||
"comfy.utils",
|
||||
"comfy.sample",
|
||||
"comfy.samplers",
|
||||
"comfy.nested_tensor",
|
||||
"comfy.model_management",
|
||||
"latent_preview",
|
||||
"node_helpers",
|
||||
"folder_paths",
|
||||
"dumas_h3_longvideos",
|
||||
"dumas_h3_longvideos_upstream",
|
||||
"dumas_h3_longvideos_engine",
|
||||
"dumas_h3_longvideos_shot_plan",
|
||||
"dumas_h3_longvideos_runtime",
|
||||
"dumas_h3_longvideos_audio",
|
||||
"dumas_h3_longvideos_conditioning",
|
||||
"h3_engine",
|
||||
"h3_shot_plan",
|
||||
"h3_runtime",
|
||||
"h3_audio",
|
||||
"h3_conditioning",
|
||||
)
|
||||
}
|
||||
|
||||
fake_torch = types.SimpleNamespace(
|
||||
cuda=types.SimpleNamespace(OutOfMemoryError=RuntimeError),
|
||||
float32="float32",
|
||||
float16="float16",
|
||||
bfloat16="bfloat16",
|
||||
zeros=lambda *args, **kwargs: None,
|
||||
empty=lambda *args, **kwargs: None,
|
||||
cat=lambda *args, **kwargs: None,
|
||||
stack=lambda *args, **kwargs: None,
|
||||
tensor=lambda *args, **kwargs: None,
|
||||
no_grad=lambda: _NullContext(),
|
||||
inference_mode=lambda: _NullContext(),
|
||||
)
|
||||
fake_nodes = types.SimpleNamespace(
|
||||
NODE_CLASS_MAPPINGS={},
|
||||
common_ksampler=lambda *args, **kwargs: ({},),
|
||||
)
|
||||
fake_comfy_samplers = types.SimpleNamespace(
|
||||
KSampler=types.SimpleNamespace(
|
||||
SAMPLERS=("res_multistep", "euler"),
|
||||
SCHEDULERS=("simple", "normal"),
|
||||
)
|
||||
)
|
||||
fake_comfy_utils = types.SimpleNamespace(ProgressBar=lambda total: None)
|
||||
fake_mm = types.SimpleNamespace(
|
||||
current_loaded_models=[],
|
||||
free_memory=lambda *args, **kwargs: None,
|
||||
get_torch_device=lambda: "cpu",
|
||||
soft_empty_cache=lambda *args, **kwargs: None,
|
||||
unload_all_models=lambda *args, **kwargs: None,
|
||||
get_free_memory=lambda *args, **kwargs: 0,
|
||||
get_total_memory=lambda *args, **kwargs: 0,
|
||||
)
|
||||
fake_comfy = types.SimpleNamespace(
|
||||
utils=fake_comfy_utils,
|
||||
sample=types.SimpleNamespace(),
|
||||
samplers=fake_comfy_samplers,
|
||||
nested_tensor=types.SimpleNamespace(),
|
||||
model_management=fake_mm,
|
||||
)
|
||||
|
||||
sys.modules["torch"] = fake_torch
|
||||
sys.modules["nodes"] = fake_nodes
|
||||
sys.modules["comfy"] = fake_comfy
|
||||
sys.modules["comfy.utils"] = fake_comfy_utils
|
||||
sys.modules["comfy.sample"] = fake_comfy.sample
|
||||
sys.modules["comfy.samplers"] = fake_comfy_samplers
|
||||
sys.modules["comfy.nested_tensor"] = fake_comfy.nested_tensor
|
||||
sys.modules["comfy.model_management"] = fake_mm
|
||||
sys.modules["latent_preview"] = types.SimpleNamespace()
|
||||
sys.modules["node_helpers"] = types.SimpleNamespace()
|
||||
sys.modules["folder_paths"] = types.SimpleNamespace(
|
||||
get_folder_paths=lambda name: [],
|
||||
get_filename_list=lambda name: [],
|
||||
get_full_path=lambda name, filename: None,
|
||||
get_temp_directory=lambda: "/tmp",
|
||||
get_output_directory=lambda: "/tmp",
|
||||
models_dir="/tmp",
|
||||
)
|
||||
|
||||
cls.module = importlib.import_module("dumas_h3_longvideos")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
for name, module in cls._saved_modules.items():
|
||||
if module is None:
|
||||
sys.modules.pop(name, None)
|
||||
else:
|
||||
sys.modules[name] = module
|
||||
|
||||
def test_dumas_key_wraps_upstream_node(self):
|
||||
mappings = self.module.NODE_CLASS_MAPPINGS
|
||||
|
||||
self.assertIs(mappings["DumasH3LongVideos"], self.module.H3LongVideos)
|
||||
self.assertIs(mappings["H3LongVideos"], self.module.H3LongVideos)
|
||||
self.assertIs(mappings["H3LongVideosREF2VA"], self.module.H3LongVideos)
|
||||
|
||||
def test_upstream_schema_is_exposed_under_dumas_key(self):
|
||||
node_cls = self.module.NODE_CLASS_MAPPINGS["DumasH3LongVideos"]
|
||||
schema = node_cls.INPUT_TYPES()
|
||||
|
||||
self.assertIn("prompt", schema["required"])
|
||||
self.assertTrue(schema["required"]["prompt"][1]["forceInput"])
|
||||
self.assertIn("first_frame", schema["optional"])
|
||||
self.assertIn("ref_image_1", schema["optional"])
|
||||
self.assertIn("latent_upscale", schema["optional"])
|
||||
self.assertIn("speech_tail_seconds", schema["optional"])
|
||||
self.assertIn("hold_camera", schema["optional"])
|
||||
self.assertIn("verbatim", schema["optional"])
|
||||
self.assertIn("handoff_frames", schema["optional"])
|
||||
self.assertEqual(schema["optional"]["handoff_frames"][1]["default"], 1)
|
||||
self.assertEqual(node_cls.RETURN_NAMES[0:4], ("images", "audio", "info", "script"))
|
||||
|
||||
def test_handoff_context_claim_names_reference_range(self):
|
||||
upstream = importlib.import_module("dumas_h3_longvideos_upstream")
|
||||
|
||||
self.assertIn("<Picture 2> through <Picture 22>", upstream.handoff_context_claim(2, 22))
|
||||
self.assertIn("no new subjects", upstream.handoff_context_claim(2, 22))
|
||||
self.assertIn("<Picture 5>", upstream.handoff_context_claim(5, 5))
|
||||
|
||||
|
||||
class _NullContext:
|
||||
def __enter__(self):
|
||||
return None
|
||||
|
||||
def __exit__(self, *_exc):
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+28
-1045
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
import importlib.util
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
|
||||
|
||||
class DumasVideoNodeTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
folder_paths = types.ModuleType("folder_paths")
|
||||
folder_paths.get_output_directory = lambda: "/tmp"
|
||||
sys.modules.setdefault("folder_paths", folder_paths)
|
||||
spec = importlib.util.spec_from_file_location("dumas_video_nodes", "dumas_video_nodes.py")
|
||||
cls.module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(cls.module)
|
||||
|
||||
def test_registers_two_generic_video_nodes(self):
|
||||
self.assertEqual(
|
||||
set(self.module.NODE_CLASS_MAPPINGS),
|
||||
{"DumasStandaloneVideo", "DumasJoinVideoClips"},
|
||||
)
|
||||
|
||||
def test_standalone_node_exposes_full_and_complete_outputs(self):
|
||||
node = self.module.DumasStandaloneVideoNode
|
||||
self.assertEqual(node.RETURN_NAMES, ("full_clip", "complete_clip", "complete_frames", "duration"))
|
||||
self.assertIn("overlap_frames", node.INPUT_TYPES()["required"])
|
||||
|
||||
def test_join_signature_contains_stream_compatibility_fields(self):
|
||||
signature = self.module._join_signature(
|
||||
{
|
||||
"streams": [
|
||||
{"codec_type": "video", "codec_name": "h264", "width": 1920, "height": 1088, "pix_fmt": "yuv420p", "r_frame_rate": "24/1"},
|
||||
{"codec_type": "audio", "codec_name": "aac", "sample_rate": "48000", "channels": 2},
|
||||
]
|
||||
}
|
||||
)
|
||||
self.assertEqual(signature, ("h264", 1920, 1088, "yuv420p", "24/1", "aac", "48000", 2))
|
||||
|
||||
def test_join_requires_a_clip(self):
|
||||
with self.assertRaises(ValueError):
|
||||
self.module.DumasJoinVideoClipsNode().join("")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user