Files
DumasNodes/tests/test_dumas_video_nodes.py
T

69 lines
2.7 KiB
Python

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_generic_video_nodes(self):
self.assertEqual(
set(self.module.NODE_CLASS_MAPPINGS),
{"DumasStandaloneVideo", "DumasPrepareContinuation", "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", "reference_frames"),
)
self.assertIn("overlap_frames", node.INPUT_TYPES()["required"])
self.assertIn("reference_frames", node.INPUT_TYPES()["required"])
def test_join_exposes_reference_frame_inputs(self):
optional = self.module.DumasJoinVideoClipsNode.INPUT_TYPES()["optional"]
self.assertEqual(optional["clip_2_reference_frames"][1]["default"], 0)
self.assertEqual(optional["clip_6_reference_frames"][1]["max"], 4096)
def test_prepare_continuation_exposes_clean_and_tail_outputs(self):
node = self.module.DumasPrepareContinuationNode
self.assertEqual(
node.RETURN_NAMES,
("clean_clip", "next_reference", "reference_frames", "clean_duration"),
)
self.assertIn("raw_clip", node.INPUT_TYPES()["required"])
def test_video_fps_parses_frame_rate(self):
self.assertEqual(
self.module._video_fps({"streams": [{"codec_type": "video", "r_frame_rate": "24/1"}]}),
24.0,
)
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()