ComfyUI/tests-unit/execution_test/test_accumulate_merge.py
bymyself c8bce44549
Some checks are pending
Python Linting / Run Ruff (push) Waiting to run
Python Linting / Run Pylint (push) Waiting to run
Build package / Build Test (3.10) (push) Waiting to run
Build package / Build Test (3.11) (push) Waiting to run
Build package / Build Test (3.12) (push) Waiting to run
Build package / Build Test (3.13) (push) Waiting to run
Build package / Build Test (3.14) (push) Waiting to run
feat: add accumulate toggle to SaveImage and PreviewImage nodes
Add 'accumulate' BOOLEAN optional input (advanced, default False) to
SaveImage and PreviewImage INPUT_TYPES. Accept the parameter in
save_images() so the execution engine can pass it through.

Set merge flag in the 'executed' websocket message when accumulate is
enabled, so the frontend appends outputs instead of replacing them.

Add unit tests for the accumulate input definition and merge flag
derivation logic.

Amp-Thread-ID: https://ampcode.com/threads/T-019cbb66-bb43-771e-b47b-0f05a436b9cb
2026-03-04 16:43:40 -08:00

90 lines
3.1 KiB
Python

"""
Unit tests for the accumulate toggle on SaveImage and PreviewImage nodes.
Tests that the accumulate input is correctly defined and that the merge flag
derivation logic in execution.py works for all input shapes.
"""
import inspect
import pytest
import nodes
class TestSaveImageAccumulateInput:
"""Test SaveImage node definition includes accumulate input."""
def test_accumulate_in_optional_inputs(self):
input_types = nodes.SaveImage.INPUT_TYPES()
assert "optional" in input_types
assert "accumulate" in input_types["optional"]
def test_accumulate_is_boolean_type(self):
input_types = nodes.SaveImage.INPUT_TYPES()
accumulate_def = input_types["optional"]["accumulate"]
assert accumulate_def[0] == "BOOLEAN"
def test_accumulate_defaults_to_false(self):
input_types = nodes.SaveImage.INPUT_TYPES()
accumulate_def = input_types["optional"]["accumulate"]
assert accumulate_def[1]["default"] is False
def test_accumulate_is_advanced(self):
input_types = nodes.SaveImage.INPUT_TYPES()
accumulate_def = input_types["optional"]["accumulate"]
assert accumulate_def[1].get("advanced") is True
def test_save_images_accepts_accumulate_parameter(self):
sig = inspect.signature(nodes.SaveImage.save_images)
assert "accumulate" in sig.parameters
assert sig.parameters["accumulate"].default is False
class TestPreviewImageAccumulateInput:
"""Test PreviewImage node definition includes accumulate input."""
def test_accumulate_in_optional_inputs(self):
input_types = nodes.PreviewImage.INPUT_TYPES()
assert "optional" in input_types
assert "accumulate" in input_types["optional"]
def test_accumulate_is_boolean_type(self):
input_types = nodes.PreviewImage.INPUT_TYPES()
accumulate_def = input_types["optional"]["accumulate"]
assert accumulate_def[0] == "BOOLEAN"
def test_accumulate_defaults_to_false(self):
input_types = nodes.PreviewImage.INPUT_TYPES()
accumulate_def = input_types["optional"]["accumulate"]
assert accumulate_def[1]["default"] is False
class TestAccumulateMergeFlagDerivation:
"""Test the merge flag logic used in execution.py.
In execution.py, the merge flag is derived as:
merge = inputs.get('accumulate') is True
This must return True only for literal True, not for truthy values
like lists (which represent node links in the prompt).
"""
@pytest.mark.parametrize(
"inputs,expected",
[
({"accumulate": True}, True),
({"accumulate": False}, False),
({}, False),
({"accumulate": None}, False),
# Node link: accumulate connected to another node's output
({"accumulate": ["other_node_id", 0]}, False),
# String "true" should not match
({"accumulate": "true"}, False),
# Integer 1 should not match
({"accumulate": 1}, False),
],
)
def test_merge_flag(self, inputs, expected):
merge = inputs.get("accumulate") is True
assert merge is expected