From 1041b092c8ce5ffac679e76ff11f539cf1f0b56f Mon Sep 17 00:00:00 2001 From: opvelll Date: Fri, 20 Mar 2026 00:03:42 +0900 Subject: [PATCH] feat: Add unit tests for ProductedString and NodeRegistration --- tests/test_Hello.py | 10 -------- tests/test_NodeRegistration.py | 36 +++++++++++++++++++++++++++ tests/test_ProductedString.py | 45 ++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 10 deletions(-) delete mode 100644 tests/test_Hello.py create mode 100644 tests/test_NodeRegistration.py create mode 100644 tests/test_ProductedString.py diff --git a/tests/test_Hello.py b/tests/test_Hello.py deleted file mode 100644 index a0ad511..0000000 --- a/tests/test_Hello.py +++ /dev/null @@ -1,10 +0,0 @@ -import unittest - - -class TestHello(unittest.TestCase): - def test_hello(self): - self.assertEqual("Hello", "Hello") - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_NodeRegistration.py b/tests/test_NodeRegistration.py new file mode 100644 index 0000000..d72d88e --- /dev/null +++ b/tests/test_NodeRegistration.py @@ -0,0 +1,36 @@ +import unittest +import importlib +from pathlib import Path +import sys + + +ROOT_DIR = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT_DIR.parent)) +PLUGIN_INIT = importlib.import_module(ROOT_DIR.name) + + +class TestNodeRegistration(unittest.TestCase): + def test_all_nodes_are_registered(self): + expected_keys = { + "TextListProduct", + "TextListProductWithSingleA", + "TextListProductWithSingleB", + "TextListProductWithSingleBoth", + "ProductedString", + "PromptPairConcat", + } + self.assertEqual(set(PLUGIN_INIT.NODE_CLASS_MAPPINGS.keys()), expected_keys) + self.assertEqual( + set(PLUGIN_INIT.NODE_DISPLAY_NAME_MAPPINGS.keys()), expected_keys + ) + + def test_registered_nodes_expose_required_comfyui_attributes(self): + for key, node_class in PLUGIN_INIT.NODE_CLASS_MAPPINGS.items(): + self.assertTrue(hasattr(node_class, "INPUT_TYPES"), key) + self.assertTrue(hasattr(node_class, "RETURN_TYPES"), key) + self.assertTrue(hasattr(node_class, "FUNCTION"), key) + self.assertTrue(hasattr(node_class, "CATEGORY"), key) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_ProductedString.py b/tests/test_ProductedString.py new file mode 100644 index 0000000..f08fde4 --- /dev/null +++ b/tests/test_ProductedString.py @@ -0,0 +1,45 @@ +import unittest + +from src.ProductedString import ProductedString + + +class TestProductedString(unittest.TestCase): + def setUp(self): + self.node = ProductedString() + + def test_combine_input_lists_two_lists(self): + result = self.node.combine_input_lists( + ", ", "\n", list_a=["a", "b"], list_b=["1", "2"] + ) + self.assertEqual(result, ("a, 1\na, 2\nb, 1\nb, 2",)) + + def test_combine_input_lists_only_connected_lists_are_used(self): + result = self.node.combine_input_lists( + " | ", + "\n", + list_a=["a"], + list_c=["1", "2"], + list_f=["x"], + ignored="not-a-list", + ) + self.assertEqual(result, ("a | 1 | x\na | 2 | x",)) + + def test_combine_input_lists_empty_when_no_lists_are_connected(self): + result = self.node.combine_input_lists(", ", "\n") + self.assertEqual(result, ("",)) + + def test_combine_input_lists_filters_empty_strings(self): + result = self.node.combine_input_lists( + ", ", "\n", list_a=["a", ""], list_b=["1", ""] + ) + self.assertEqual(result, ("a, 1\na\n1",)) + + def test_combine_input_lists_uses_custom_newline_character(self): + result = self.node.combine_input_lists( + ", ", " / ", list_a=["a"], list_b=["1", "2"] + ) + self.assertEqual(result, ("a, 1 / a, 2",)) + + +if __name__ == "__main__": + unittest.main()