diff --git a/__init__.py b/__init__.py index 1473f8c..da02945 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,6 @@ -from create_n_token_node import CreateNTokenStringNode +from .create_n_token_node import CreateNTokenStringNode - -NODE_CLASS_MAPPINGS = { "wutipong/comfyui-textutils/create-n-token-string" : CreateNTokenStringNode } -NODE_DISPLAY_NAME_MAPPINGS = { "wutipong/comfyui-textutils/create-n-token-string" : "Create N-Token String" } \ No newline at end of file +NODE_CLASS_MAPPINGS = { + "wutipong/comfyui-textutils/create-n-token-string": CreateNTokenStringNode} +NODE_DISPLAY_NAME_MAPPINGS = { + "wutipong/comfyui-textutils/create-n-token-string": "Create N-Token String"} diff --git a/create_n_token_node.py b/create_n_token_node.py index 5c1d513..69d06a9 100644 --- a/create_n_token_node.py +++ b/create_n_token_node.py @@ -1,21 +1,21 @@ -import textutils +from .textutils import create_n_token_string class CreateNTokenStringNode: @classmethod def INPUT_TYPES(cls): return { - "required": { - "text" : ("TEXT", ""), - "delim": ("TEXT", ""), - "n": ("INT", 0) + "required": { + "text": ("STRING", {"default": ""}), + "separator": ("STRING", {"default": "/"}), + "n": ("INT", {"default": 0, "min": -100, "max": 100, "step": 1}) }, } - RETURN_TYPES = ("Text",) + RETURN_TYPES = ("STRING",) RETURN_NAMES = ("TEXT",) - FUNCTION = "create_n_token_string" - CATEGORY = "wutipong" + FUNCTION = "perform_create_n_token_string" + CATEGORY = "text utility" - def create_n_token_string(self, text, delim, n): - return (textutils.create_n_token_string(text, delim, n),) \ No newline at end of file + def perform_create_n_token_string(self, text, delim, n): + return (create_n_token_string(text, delim, n),) diff --git a/test_textutitls.py b/test_textutitls.py index 6eab7c6..c611a91 100644 --- a/test_textutitls.py +++ b/test_textutitls.py @@ -1,29 +1,42 @@ import textutils import unittest + class TestTextUtils(unittest.TestCase): def test_positive_tokens(self): - self.assertEqual(textutils.create_n_token_string("hello/world/how/are/you/doing", "/", 0), "") - self.assertEqual(textutils.create_n_token_string("hello/world/how/are/you/doing", "/", 1), "hello") - self.assertEqual(textutils.create_n_token_string("hello/world/how/are/you/doing", "/", 2), "hello/world") + self.assertEqual(textutils.create_n_token_string( + "hello/world/how/are/you/doing", "/", 0), "") + self.assertEqual(textutils.create_n_token_string( + "hello/world/how/are/you/doing", "/", 1), "hello") + self.assertEqual(textutils.create_n_token_string( + "hello/world/how/are/you/doing", "/", 2), "hello/world") - def test_negative_tokens(self): - self.assertEqual(textutils.create_n_token_string("hello/world/how/are/you/doing", "/", -1), "doing") - self.assertEqual(textutils.create_n_token_string("hello/world/how/are/you/doing", "/", -2), "you/doing") + self.assertEqual(textutils.create_n_token_string( + "hello/world/how/are/you/doing", "/", -1), "doing") + self.assertEqual(textutils.create_n_token_string( + "hello/world/how/are/you/doing", "/", -2), "you/doing") def test_n_exceed_length(self): - self.assertEqual(textutils.create_n_token_string("hello/world/how/are/you/doing", "/", 8), "hello/world/how/are/you/doing") - self.assertEqual(textutils.create_n_token_string("hello/world/how/are/you/doing", "/", -6), "hello/world/how/are/you/doing") + self.assertEqual(textutils.create_n_token_string( + "hello/world/how/are/you/doing", "/", 8), "hello/world/how/are/you/doing") + self.assertEqual(textutils.create_n_token_string( + "hello/world/how/are/you/doing", "/", -6), "hello/world/how/are/you/doing") def test_delim_at_the_begining(self): - self.assertEqual(textutils.create_n_token_string("/hello/world/how/are/you/doing/", "/", 0), "") - self.assertEqual(textutils.create_n_token_string("/hello/world/how/are/you/doing/", "/", 1), "") - self.assertEqual(textutils.create_n_token_string("/hello/world/how/are/you/doing/", "/", 2), "/hello") + self.assertEqual(textutils.create_n_token_string( + "/hello/world/how/are/you/doing/", "/", 0), "") + self.assertEqual(textutils.create_n_token_string( + "/hello/world/how/are/you/doing/", "/", 1), "") + self.assertEqual(textutils.create_n_token_string( + "/hello/world/how/are/you/doing/", "/", 2), "/hello") def test_delim_at_the_end(self): - self.assertEqual(textutils.create_n_token_string("hello/world/how/are/you/doing/", "/", -1), "") - self.assertEqual(textutils.create_n_token_string("hello/world/how/are/you/doing/", "/", -2), "doing/") + self.assertEqual(textutils.create_n_token_string( + "hello/world/how/are/you/doing/", "/", -1), "") + self.assertEqual(textutils.create_n_token_string( + "hello/world/how/are/you/doing/", "/", -2), "doing/") + if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/textutils.py b/textutils.py index 9391a6e..4d720cf 100644 --- a/textutils.py +++ b/textutils.py @@ -1,11 +1,12 @@ def create_n_token_string(str, delim, n): parts = str.split(delim) - if n > 0 : + if n > 0: return delim.join(parts[0: n]) - else : + else: l = len(parts) start = l + n - if start < 0: start = 0 + if start < 0: + start = 0 - return delim.join(parts[start: l]) \ No newline at end of file + return delim.join(parts[start: l])