Skip to content

Commit 195af21

Browse files
committed
Test compare function.
1 parent 7fe9a9e commit 195af21

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

src/validate_nodes.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,37 +104,6 @@ def compare_return_types(node_name: str, base_class: Type, pr_class: Type) -> li
104104

105105
return changes
106106

107-
def compare_input_types(node_name: str, base_class: Type, pr_class: Type) -> list[BreakingChange]:
108-
"""Compare INPUT_TYPES between base and PR versions of a node."""
109-
changes = []
110-
111-
base_inputs = base_class.INPUT_TYPES().get("required", {})
112-
pr_inputs = pr_class.INPUT_TYPES().get("required", {})
113-
114-
# Check for removed inputs
115-
for input_name, input_config in base_inputs.items():
116-
if input_name not in pr_inputs:
117-
changes.append(BreakingChange(
118-
node_name=node_name,
119-
change_type=BreakingChangeType.INPUT_REMOVED,
120-
details=f"Required input '{input_name}' was removed",
121-
base_value=input_config,
122-
pr_value=None
123-
))
124-
continue
125-
126-
# Check input type changes
127-
if pr_inputs[input_name][0] != input_config[0]:
128-
changes.append(BreakingChange(
129-
node_name=node_name,
130-
change_type=BreakingChangeType.INPUT_TYPE_CHANGED,
131-
details=f"Input type changed for '{input_name}'",
132-
base_value=input_config[0],
133-
pr_value=pr_inputs[input_name][0]
134-
))
135-
136-
return changes
137-
138107
def compare_function(node_name: str, base_class: Type, pr_class: Type) -> list[BreakingChange]:
139108
"""Compare FUNCTION attribute between base and PR versions of a node."""
140109
changes = []
@@ -171,7 +140,6 @@ def compare_nodes(base_nodes: Dict[str, Type], pr_nodes: Dict[str, Type]) -> lis
171140
pr_class = pr_nodes[node_name]
172141

173142
changes.extend(compare_return_types(node_name, base_class, pr_class))
174-
changes.extend(compare_input_types(node_name, base_class, pr_class))
175143
changes.extend(compare_function(node_name, base_class, pr_class))
176144

177145
return changes

tests/test_validate_nodes.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,44 @@ def test_compare_return_types_missing():
5858
assert changes[0].change_type == BreakingChangeType.RETURN_TYPES_CHANGED
5959
assert changes[0].base_value == ("STRING", "INT", "FLOAT")
6060
assert changes[0].pr_value == tuple()
61+
62+
63+
def test_compare_function():
64+
from src.validate_nodes import compare_function, BreakingChangeType
65+
66+
class BaseNode:
67+
FUNCTION = "process"
68+
69+
class PRNode:
70+
FUNCTION = "process"
71+
72+
class ChangedNode:
73+
FUNCTION = "different_process"
74+
75+
class NoFunctionNode:
76+
pass
77+
78+
# Test 1: No changes
79+
changes = compare_function("TestNode", BaseNode, PRNode)
80+
assert len(changes) == 0
81+
82+
# Test 2: Function changed
83+
changes = compare_function("TestNode", BaseNode, ChangedNode)
84+
assert len(changes) == 1
85+
assert changes[0].change_type == BreakingChangeType.FUNCTION_CHANGED
86+
assert changes[0].base_value == "process"
87+
assert changes[0].pr_value == "different_process"
88+
89+
# Test 3: Function removed
90+
changes = compare_function("TestNode", BaseNode, NoFunctionNode)
91+
assert len(changes) == 1
92+
assert changes[0].change_type == BreakingChangeType.FUNCTION_CHANGED
93+
assert changes[0].base_value == "process"
94+
assert changes[0].pr_value is None
95+
96+
# Test 4: Function added (not a breaking change if base had none)
97+
changes = compare_function("TestNode", NoFunctionNode, BaseNode)
98+
assert len(changes) == 1
99+
assert changes[0].change_type == BreakingChangeType.FUNCTION_CHANGED
100+
assert changes[0].base_value is None
101+
assert changes[0].pr_value == "process"

0 commit comments

Comments
 (0)