formatAnyInputName / _first_nonempty_any を追加し、Prettier で整形。 Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""Any Switch (misc) の switch ロジック(ComfyUI 不要)"""
|
|
|
|
import unittest
|
|
|
|
from py.any_switch import MiscAnySwitch
|
|
|
|
class TestMiscAnySwitch(unittest.TestCase):
|
|
def setUp(self):
|
|
self.node = MiscAnySwitch()
|
|
self.latent = {"samples": "fake_latent"}
|
|
|
|
def test_auto_skips_empty_any_01_and_uses_any_02(self):
|
|
value, index = self.node.switch(select_index=-1, any_01=None, any_02=self.latent)
|
|
self.assertEqual(value, self.latent)
|
|
self.assertEqual(index, 1)
|
|
|
|
def test_fixed_index_falls_back_when_target_empty(self):
|
|
value, index = self.node.switch(select_index=0, any_02=self.latent)
|
|
self.assertEqual(value, self.latent)
|
|
self.assertEqual(index, 1)
|
|
|
|
def test_fixed_index_uses_target_when_connected(self):
|
|
other = {"samples": "other"}
|
|
value, index = self.node.switch(select_index=0, any_01=other, any_02=self.latent)
|
|
self.assertEqual(value, other)
|
|
self.assertEqual(index, 0)
|
|
|
|
def test_sorted_any_inputs_pick_lowest_index(self):
|
|
value, index = self.node.switch(
|
|
select_index=-1,
|
|
any_02=self.latent,
|
|
any_01={"samples": "first"},
|
|
)
|
|
self.assertEqual(value, {"samples": "first"})
|
|
self.assertEqual(index, 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|