feat: Add unit tests for ProductedString and NodeRegistration
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
import unittest
|
||||
|
||||
|
||||
class TestHello(unittest.TestCase):
|
||||
def test_hello(self):
|
||||
self.assertEqual("Hello", "Hello")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -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()
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user