Skip to content

Commit a584e8d

Browse files
authored
Merge pull request #1 from StableLlama/more_tests
Add more unit tests
2 parents 94e9a5c + 867ead6 commit a584e8d

15 files changed

+472
-628
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "basic_data_handling"
7-
version = "0.0.8"
7+
version = "0.0.9"
88
description = """NOTE: Still in development! Expect breaking changes!
99
Basic Python functions for manipulating data that every programmer is used to.
1010
Currently supported ComfyUI data types: BOOLEAN, FLOAT, INT, STRING and data lists.

src/basic_data_handling/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from . import (boolean_nodes, casting_nodes, comparison_nodes, control_flow,
1+
from . import (boolean_nodes, casting_nodes, comparison_nodes, control_flow_nodes,
22
data_list_nodes, dict_nodes, float_nodes, int_nodes, list_nodes,
33
math_nodes, path_nodes, regex_nodes, set_nodes, string_nodes)
44

55
NODE_CLASS_MAPPINGS = {}
66
NODE_CLASS_MAPPINGS.update(boolean_nodes.NODE_CLASS_MAPPINGS)
77
NODE_CLASS_MAPPINGS.update(casting_nodes.NODE_CLASS_MAPPINGS)
88
NODE_CLASS_MAPPINGS.update(comparison_nodes.NODE_CLASS_MAPPINGS)
9-
NODE_CLASS_MAPPINGS.update(control_flow.NODE_CLASS_MAPPINGS)
9+
NODE_CLASS_MAPPINGS.update(control_flow_nodes.NODE_CLASS_MAPPINGS)
1010
NODE_CLASS_MAPPINGS.update(data_list_nodes.NODE_CLASS_MAPPINGS)
1111
NODE_CLASS_MAPPINGS.update(dict_nodes.NODE_CLASS_MAPPINGS)
1212
NODE_CLASS_MAPPINGS.update(float_nodes.NODE_CLASS_MAPPINGS)
@@ -22,7 +22,7 @@
2222
NODE_DISPLAY_NAME_MAPPINGS.update(boolean_nodes.NODE_DISPLAY_NAME_MAPPINGS)
2323
NODE_DISPLAY_NAME_MAPPINGS.update(casting_nodes.NODE_DISPLAY_NAME_MAPPINGS)
2424
NODE_DISPLAY_NAME_MAPPINGS.update(comparison_nodes.NODE_DISPLAY_NAME_MAPPINGS)
25-
NODE_DISPLAY_NAME_MAPPINGS.update(control_flow.NODE_DISPLAY_NAME_MAPPINGS)
25+
NODE_DISPLAY_NAME_MAPPINGS.update(control_flow_nodes.NODE_DISPLAY_NAME_MAPPINGS)
2626
NODE_DISPLAY_NAME_MAPPINGS.update(data_list_nodes.NODE_DISPLAY_NAME_MAPPINGS)
2727
NODE_DISPLAY_NAME_MAPPINGS.update(dict_nodes.NODE_DISPLAY_NAME_MAPPINGS)
2828
NODE_DISPLAY_NAME_MAPPINGS.update(float_nodes.NODE_DISPLAY_NAME_MAPPINGS)

src/basic_data_handling/casting_nodes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
5151
def convert_to_int(self, input: Any) -> tuple[int]:
5252
try:
5353
return (int(input),)
54-
except ValueError:
54+
except (ValueError, TypeError):
5555
raise ValueError(f"Cannot convert {input} to an INT.")
5656

5757

@@ -79,7 +79,7 @@ def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
7979
def convert_to_float(self, input: Any) -> tuple[float]:
8080
try:
8181
return (float(input),)
82-
except ValueError:
82+
except (ValueError, TypeError):
8383
raise ValueError(f"Cannot convert {input} to a FLOAT.")
8484

8585

@@ -161,7 +161,7 @@ def INPUT_TYPES(cls):
161161
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
162162
return True
163163

164-
def convert(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
164+
def convert(self, **kwargs: list[Any]) -> tuple[list[Any]]:
165165
return (kwargs.get('list', []).copy(),)
166166

167167

@@ -218,7 +218,7 @@ def INPUT_TYPES(cls):
218218
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
219219
return True
220220

221-
def convert(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
221+
def convert(self, **kwargs: list[Any]) -> tuple[set[Any]]:
222222
return (set(kwargs.get('list', [])),)
223223

224224

src/basic_data_handling/control_flow.py renamed to src/basic_data_handling/control_flow_nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Union
1+
from typing import Any
22
from inspect import cleandoc
33

44
class IfElse:

src/basic_data_handling/data_list_nodes.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def INPUT_TYPES(cls):
3030
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
3131
return True
3232

33-
def append(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
33+
def append(self, **kwargs: list[Any]) -> tuple[list[Any]]:
3434
result = kwargs.get('list', []).copy()
3535
item = kwargs.get('item', [])
3636
if len(item) > 0:
@@ -66,7 +66,7 @@ def INPUT_TYPES(cls):
6666
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
6767
return True
6868

69-
def extend(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
69+
def extend(self, **kwargs: list[Any]) -> tuple[list[Any]]:
7070
return (kwargs.get('list_a', []) + kwargs.get('list_b', []),)
7171

7272

@@ -99,7 +99,7 @@ def INPUT_TYPES(cls):
9999
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
100100
return True
101101

102-
def insert(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
102+
def insert(self, **kwargs: list[Any]) -> tuple[list[Any]]:
103103
result = kwargs.get('list', []).copy()
104104
result.insert(kwargs.get('index', [0])[0], kwargs.get('item', [None])[0])
105105
return (result,)
@@ -133,7 +133,7 @@ def INPUT_TYPES(cls):
133133
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
134134
return True
135135

136-
def remove(self, **kwargs: dict[str, list]) -> tuple[list[Any], bool]:
136+
def remove(self, **kwargs: list[Any]) -> tuple[list[Any], bool]:
137137
result = kwargs.get('list', []).copy()
138138
value = kwargs.get('value', [])
139139
try:
@@ -172,12 +172,12 @@ def INPUT_TYPES(cls):
172172
OUTPUT_IS_LIST = (True, False)
173173

174174
@classmethod
175-
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool|str:
176-
if input_types[0].get("index", "INT") not in ("INT"):
175+
def VALIDATE_INPUTS(cls, input_types: list[dict[str, str]]) -> bool|str:
176+
if input_types[0].get("index", "INT") != "INT":
177177
return "index must be an INT type"
178178
return True
179179

180-
def pop(self, **kwargs: dict[str, list]) -> tuple[list[Any], Any]:
180+
def pop(self, **kwargs: list[Any]) -> tuple[list[Any], Any]:
181181
result = kwargs.get('list', []).copy()
182182
index = kwargs.get('index', [-1])[0]
183183
try:
@@ -213,7 +213,7 @@ def INPUT_TYPES(cls):
213213
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
214214
return True
215215

216-
def clear(self, **kwargs: dict[str, list]) -> tuple[[]]:
216+
def clear(self, **kwargs: list[Any]) -> tuple[list]:
217217
# Return a new empty list rather than modifying the input
218218
return ([],)
219219

@@ -250,7 +250,7 @@ def INPUT_TYPES(cls):
250250
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
251251
return True
252252

253-
def list_index(self, **kwargs: dict[str, list]) -> tuple[int]:
253+
def list_index(self, **kwargs: list[Any]) -> tuple[int]:
254254
input_list = kwargs.get('list', [])
255255
value = kwargs.get('value', [None])[0]
256256
start = kwargs.get('start', [0])[0]
@@ -291,7 +291,7 @@ def INPUT_TYPES(cls):
291291
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
292292
return True
293293

294-
def count(self, **kwargs: dict[str, list]) -> tuple[int]:
294+
def count(self, **kwargs: list[Any]) -> tuple[int]:
295295
value = kwargs.get('value', [None])[0]
296296
return (kwargs.get('list', []).count(value),)
297297

@@ -326,7 +326,7 @@ def INPUT_TYPES(cls):
326326
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
327327
return True
328328

329-
def sort(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
329+
def sort(self, **kwargs: list[Any]) -> tuple[list[Any]]:
330330
# Convert string to boolean
331331
reverse = kwargs.get('reverse', ["False"])[0] == "True"
332332

@@ -360,7 +360,7 @@ def INPUT_TYPES(cls):
360360
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
361361
return True
362362

363-
def reverse(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
363+
def reverse(self, **kwargs: list[Any]) -> tuple[list[Any]]:
364364
result = kwargs.get('list', []).copy()
365365
result.reverse()
366366
return (result,)
@@ -392,7 +392,7 @@ def INPUT_TYPES(cls):
392392
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
393393
return True
394394

395-
def copy(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
395+
def copy(self, **kwargs: list[Any]) -> tuple[list[Any]]:
396396
return (kwargs.get('list', []).copy(),)
397397

398398

@@ -421,7 +421,7 @@ def INPUT_TYPES(cls):
421421
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
422422
return True
423423

424-
def length(self, **kwargs: dict[str, list]) -> tuple[int]:
424+
def length(self, **kwargs: list[Any]) -> tuple[int]:
425425
return (len(kwargs.get('list', [])),)
426426

427427

@@ -457,7 +457,7 @@ def INPUT_TYPES(cls):
457457
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
458458
return True
459459

460-
def slice(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
460+
def slice(self, **kwargs: list[Any]) -> tuple[list[Any]]:
461461
input_list = kwargs.get('list', [])
462462
start = kwargs.get('start', [0])[0]
463463
stop = kwargs.get('stop', [-1])[0]
@@ -481,7 +481,7 @@ class DataListGetItem:
481481
def INPUT_TYPES(cls):
482482
return {
483483
"required": {
484-
"input_list": ("*",),
484+
"list": ("*",),
485485
"index": ("INT", {"default": 0}),
486486
}
487487
}
@@ -497,7 +497,7 @@ def INPUT_TYPES(cls):
497497
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
498498
return True
499499

500-
def get_item(self, **kwargs: dict[str, list]) -> tuple[Any]:
500+
def get_item(self, **kwargs: list[Any]) -> tuple[Any]:
501501
index = kwargs.get('index', [0])[0]
502502
try:
503503
return (kwargs.get('list', [])[index],)
@@ -534,7 +534,7 @@ def INPUT_TYPES(cls):
534534
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
535535
return True
536536

537-
def set_item(self, **kwargs: dict[str, list]) -> tuple[Any]:
537+
def set_item(self, **kwargs: list[Any]) -> tuple[Any]:
538538
input_list = kwargs.get('list', [])
539539
index = kwargs.get('index', [0])[0]
540540
value = kwargs.get('value', [None])[0]
@@ -557,7 +557,7 @@ class DataListContains:
557557
def INPUT_TYPES(cls):
558558
return {
559559
"required": {
560-
"input_list": ("*",),
560+
"list": ("*",),
561561
"value": ("*",),
562562
}
563563
}
@@ -573,7 +573,7 @@ def INPUT_TYPES(cls):
573573
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
574574
return True
575575

576-
def contains(self, **kwargs: dict[str, list]) -> tuple[bool]:
576+
def contains(self, **kwargs: list[Any]) -> tuple[bool]:
577577
value = kwargs.get('value', [])
578578
if len(value) == 0:
579579
return (False,)
@@ -597,7 +597,7 @@ def INPUT_TYPES(cls):
597597
FUNCTION = "create_empty"
598598
OUTPUT_IS_LIST = (True,)
599599

600-
def create_empty(self) -> tuple[[]]:
600+
def create_empty(self) -> tuple[list]:
601601
return ([],)
602602

603603

@@ -634,7 +634,7 @@ def INPUT_TYPES(cls):
634634
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool:
635635
return True
636636

637-
def zip_lists(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
637+
def zip_lists(self, **kwargs: list[Any]) -> tuple[list[Any]]:
638638
lists = [kwargs.get('list1', []), kwargs.get('list2', [])]
639639

640640
if 'list3' in kwargs:
@@ -677,12 +677,12 @@ def INPUT_TYPES(cls):
677677
OUTPUT_IS_LIST = (True,)
678678

679679
@classmethod
680-
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool|str:
681-
if input_types[0]["filter"] not in ("BOOLEAN"):
680+
def VALIDATE_INPUTS(cls, input_types: list[dict[str, str]]) -> bool|str:
681+
if input_types[0]["filter"] != "BOOLEAN":
682682
return "filter must be a BOOLEAN type"
683683
return True
684684

685-
def filter_data(self, **kwargs: dict[str, list]) -> tuple[list[Any]]:
685+
def filter_data(self, **kwargs: list[Any]) -> tuple[list[Any]]:
686686
values = kwargs.get('value', [])
687687
filters = kwargs.get('filter', [])
688688

@@ -716,12 +716,12 @@ def INPUT_TYPES(cls):
716716
INPUT_IS_LIST = True
717717

718718
@classmethod
719-
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool|str:
719+
def VALIDATE_INPUTS(cls, input_types: list[dict[str, str]]) -> bool|str:
720720
if input_types[0]["list"] not in ("FLOAT", "INT"):
721721
return "list must contain FLOAT or INT types"
722722
return True
723723

724-
def find_min(self, **kwargs: dict[str, list]) -> tuple[Any]:
724+
def find_min(self, **kwargs: list[Any]) -> tuple[Any]:
725725
values = kwargs.get('list', [])
726726
if not values:
727727
return (None,)
@@ -758,12 +758,12 @@ def INPUT_TYPES(cls):
758758
INPUT_IS_LIST = True
759759

760760
@classmethod
761-
def VALIDATE_INPUTS(cls, input_types: dict[str, str]) -> bool|str:
761+
def VALIDATE_INPUTS(cls, input_types: list[dict[str, str]]) -> bool|str:
762762
if input_types[0]["list"] not in ("FLOAT", "INT"):
763763
return "list must contain FLOAT or INT types"
764764
return True
765765

766-
def find_max(self, **kwargs: dict[str, list]) -> tuple[Any]:
766+
def find_max(self, **kwargs: list[Any]) -> tuple[Any]:
767767
values = kwargs.get('list', [])
768768
if not values:
769769
return (None,)

src/basic_data_handling/dict_nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def popitem(self, input_dict: dict) -> tuple[dict, str, Any, bool]:
353353
return result, key, value, True
354354
else:
355355
return result, "", None, False
356-
except Exception as e:
356+
except:
357357
return result, "", None, False
358358

359359

src/basic_data_handling/int_nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def INPUT_TYPES(cls):
201201
DESCRIPTION = cleandoc(__doc__ or "")
202202
FUNCTION = "to_bytes"
203203

204-
def to_bytes(self, int_value: int, length: int, byteorder: Literal["big", "little"], signed: Literal["True", "False"]) -> tuple[int]:
204+
def to_bytes(self, int_value: int, length: int, byteorder: Literal["big", "little"], signed: Literal["True", "False"]) -> tuple[bytes]:
205205
signed_bool = (signed == "True")
206206
return (int_value.to_bytes(length, byteorder=byteorder, signed=signed_bool),)
207207

src/basic_data_handling/regex_nodes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import Any
21
from inspect import cleandoc
32
import re
43

0 commit comments

Comments
 (0)