| @@ -1,47 +0,0 @@ | |||
| #!/usr/bin/env python3 | |||
| """ | |||
| Simple test to verify boolean classes can be imported correctly. | |||
| """ | |||
| import sys | |||
| import os | |||
| # Add the api directory to the Python path | |||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "api")) | |||
| try: | |||
| # Test that we can import the boolean classes | |||
| from core.variables.segments import BooleanSegment, ArrayBooleanSegment | |||
| from core.variables.variables import BooleanVariable, ArrayBooleanVariable | |||
| from core.variables.types import SegmentType | |||
| print("✅ Successfully imported BooleanSegment") | |||
| print("✅ Successfully imported ArrayBooleanSegment") | |||
| print("✅ Successfully imported BooleanVariable") | |||
| print("✅ Successfully imported ArrayBooleanVariable") | |||
| print("✅ Successfully imported SegmentType") | |||
| # Test that the segment types exist | |||
| print(f"✅ SegmentType.BOOLEAN = {SegmentType.BOOLEAN}") | |||
| print(f"✅ SegmentType.ARRAY_BOOLEAN = {SegmentType.ARRAY_BOOLEAN}") | |||
| # Test creating boolean segments directly | |||
| bool_seg = BooleanSegment(value=True) | |||
| print(f"✅ Created BooleanSegment: {bool_seg}") | |||
| print(f" Value type: {bool_seg.value_type}") | |||
| print(f" Value: {bool_seg.value}") | |||
| array_bool_seg = ArrayBooleanSegment(value=[True, False, True]) | |||
| print(f"✅ Created ArrayBooleanSegment: {array_bool_seg}") | |||
| print(f" Value type: {array_bool_seg.value_type}") | |||
| print(f" Value: {array_bool_seg.value}") | |||
| print("\n🎉 All boolean class imports and basic functionality work correctly!") | |||
| except ImportError as e: | |||
| print(f"❌ Import error: {e}") | |||
| except Exception as e: | |||
| print(f"❌ Error: {e}") | |||
| import traceback | |||
| traceback.print_exc() | |||
| @@ -1,118 +0,0 @@ | |||
| #!/usr/bin/env python3 | |||
| """ | |||
| Simple test script to verify boolean condition support in IfElseNode | |||
| """ | |||
| import sys | |||
| import os | |||
| # Add the api directory to the Python path | |||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "api")) | |||
| from core.workflow.utils.condition.processor import ( | |||
| ConditionProcessor, | |||
| _evaluate_condition, | |||
| ) | |||
| def test_boolean_conditions(): | |||
| """Test boolean condition evaluation""" | |||
| print("Testing boolean condition support...") | |||
| # Test boolean "is" operator | |||
| result = _evaluate_condition(value=True, operator="is", expected="true") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean 'is' with True value passed") | |||
| result = _evaluate_condition(value=False, operator="is", expected="false") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean 'is' with False value passed") | |||
| # Test boolean "is not" operator | |||
| result = _evaluate_condition(value=True, operator="is not", expected="false") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean 'is not' with True value passed") | |||
| result = _evaluate_condition(value=False, operator="is not", expected="true") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean 'is not' with False value passed") | |||
| # Test boolean "=" operator | |||
| result = _evaluate_condition(value=True, operator="=", expected="1") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean '=' with True=1 passed") | |||
| result = _evaluate_condition(value=False, operator="=", expected="0") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean '=' with False=0 passed") | |||
| # Test boolean "≠" operator | |||
| result = _evaluate_condition(value=True, operator="≠", expected="0") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean '≠' with True≠0 passed") | |||
| result = _evaluate_condition(value=False, operator="≠", expected="1") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean '≠' with False≠1 passed") | |||
| # Test boolean "in" operator | |||
| result = _evaluate_condition(value=True, operator="in", expected=["true", "false"]) | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean 'in' with True in array passed") | |||
| result = _evaluate_condition(value=False, operator="in", expected=["true", "false"]) | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean 'in' with False in array passed") | |||
| # Test boolean "not in" operator | |||
| result = _evaluate_condition(value=True, operator="not in", expected=["false", "0"]) | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean 'not in' with True not in [false, 0] passed") | |||
| # Test boolean "null" and "not null" operators | |||
| result = _evaluate_condition(value=True, operator="not null", expected=None) | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean 'not null' with True passed") | |||
| result = _evaluate_condition(value=False, operator="not null", expected=None) | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Boolean 'not null' with False passed") | |||
| print("\n🎉 All boolean condition tests passed!") | |||
| def test_backward_compatibility(): | |||
| """Test that existing string and number conditions still work""" | |||
| print("\nTesting backward compatibility...") | |||
| # Test string conditions | |||
| result = _evaluate_condition(value="hello", operator="is", expected="hello") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ String 'is' condition still works") | |||
| result = _evaluate_condition(value="hello", operator="contains", expected="ell") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ String 'contains' condition still works") | |||
| # Test number conditions | |||
| result = _evaluate_condition(value=42, operator="=", expected="42") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Number '=' condition still works") | |||
| result = _evaluate_condition(value=42, operator=">", expected="40") | |||
| assert result == True, f"Expected True, got {result}" | |||
| print("✓ Number '>' condition still works") | |||
| print("✓ Backward compatibility maintained!") | |||
| if __name__ == "__main__": | |||
| try: | |||
| test_boolean_conditions() | |||
| test_backward_compatibility() | |||
| print( | |||
| "\n✅ All tests passed! Boolean support has been successfully added to IfElseNode." | |||
| ) | |||
| except Exception as e: | |||
| print(f"\n❌ Test failed: {e}") | |||
| sys.exit(1) | |||
| @@ -1,67 +0,0 @@ | |||
| #!/usr/bin/env python3 | |||
| """ | |||
| Test script to verify the boolean array comparison fix in condition processor. | |||
| """ | |||
| import sys | |||
| import os | |||
| # Add the api directory to the Python path | |||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "api")) | |||
| from core.workflow.utils.condition.processor import ( | |||
| _assert_contains, | |||
| _assert_not_contains, | |||
| ) | |||
| def test_boolean_array_contains(): | |||
| """Test that boolean arrays work correctly with string comparisons.""" | |||
| # Test case 1: Boolean array [True, False, True] contains "true" | |||
| bool_array = [True, False, True] | |||
| # Should return True because "true" converts to True and True is in the array | |||
| result1 = _assert_contains(value=bool_array, expected="true") | |||
| print(f"Test 1 - [True, False, True] contains 'true': {result1}") | |||
| assert result1 == True, "Expected True but got False" | |||
| # Should return True because "false" converts to False and False is in the array | |||
| result2 = _assert_contains(value=bool_array, expected="false") | |||
| print(f"Test 2 - [True, False, True] contains 'false': {result2}") | |||
| assert result2 == True, "Expected True but got False" | |||
| # Test case 2: Boolean array [True, True] does not contain "false" | |||
| bool_array2 = [True, True] | |||
| result3 = _assert_contains(value=bool_array2, expected="false") | |||
| print(f"Test 3 - [True, True] contains 'false': {result3}") | |||
| assert result3 == False, "Expected False but got True" | |||
| # Test case 3: Test not_contains | |||
| result4 = _assert_not_contains(value=bool_array2, expected="false") | |||
| print(f"Test 4 - [True, True] not contains 'false': {result4}") | |||
| assert result4 == True, "Expected True but got False" | |||
| result5 = _assert_not_contains(value=bool_array, expected="true") | |||
| print(f"Test 5 - [True, False, True] not contains 'true': {result5}") | |||
| assert result5 == False, "Expected False but got True" | |||
| # Test case 4: Test with different string representations | |||
| result6 = _assert_contains( | |||
| value=bool_array, expected="1" | |||
| ) # "1" should convert to True | |||
| print(f"Test 6 - [True, False, True] contains '1': {result6}") | |||
| assert result6 == True, "Expected True but got False" | |||
| result7 = _assert_contains( | |||
| value=bool_array, expected="0" | |||
| ) # "0" should convert to False | |||
| print(f"Test 7 - [True, False, True] contains '0': {result7}") | |||
| assert result7 == True, "Expected True but got False" | |||
| print("\n✅ All boolean array comparison tests passed!") | |||
| if __name__ == "__main__": | |||
| test_boolean_array_contains() | |||
| @@ -1,99 +0,0 @@ | |||
| #!/usr/bin/env python3 | |||
| """ | |||
| Simple test script to verify boolean type inference in variable factory. | |||
| """ | |||
| import sys | |||
| import os | |||
| # Add the api directory to the Python path | |||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "api")) | |||
| try: | |||
| from factories.variable_factory import build_segment, segment_to_variable | |||
| from core.variables.segments import BooleanSegment, ArrayBooleanSegment | |||
| from core.variables.variables import BooleanVariable, ArrayBooleanVariable | |||
| from core.variables.types import SegmentType | |||
| def test_boolean_inference(): | |||
| print("Testing boolean type inference...") | |||
| # Test single boolean values | |||
| true_segment = build_segment(True) | |||
| false_segment = build_segment(False) | |||
| print(f"True value: {true_segment}") | |||
| print(f"Type: {type(true_segment)}") | |||
| print(f"Value type: {true_segment.value_type}") | |||
| print(f"Is BooleanSegment: {isinstance(true_segment, BooleanSegment)}") | |||
| print(f"\nFalse value: {false_segment}") | |||
| print(f"Type: {type(false_segment)}") | |||
| print(f"Value type: {false_segment.value_type}") | |||
| print(f"Is BooleanSegment: {isinstance(false_segment, BooleanSegment)}") | |||
| # Test array of booleans | |||
| bool_array_segment = build_segment([True, False, True]) | |||
| print(f"\nBoolean array: {bool_array_segment}") | |||
| print(f"Type: {type(bool_array_segment)}") | |||
| print(f"Value type: {bool_array_segment.value_type}") | |||
| print( | |||
| f"Is ArrayBooleanSegment: {isinstance(bool_array_segment, ArrayBooleanSegment)}" | |||
| ) | |||
| # Test empty boolean array | |||
| empty_bool_array = build_segment([]) | |||
| print(f"\nEmpty array: {empty_bool_array}") | |||
| print(f"Type: {type(empty_bool_array)}") | |||
| print(f"Value type: {empty_bool_array.value_type}") | |||
| # Test segment to variable conversion | |||
| bool_var = segment_to_variable( | |||
| segment=true_segment, selector=["test", "bool_var"], name="test_boolean" | |||
| ) | |||
| print(f"\nBoolean variable: {bool_var}") | |||
| print(f"Type: {type(bool_var)}") | |||
| print(f"Is BooleanVariable: {isinstance(bool_var, BooleanVariable)}") | |||
| array_bool_var = segment_to_variable( | |||
| segment=bool_array_segment, | |||
| selector=["test", "array_bool_var"], | |||
| name="test_array_boolean", | |||
| ) | |||
| print(f"\nArray boolean variable: {array_bool_var}") | |||
| print(f"Type: {type(array_bool_var)}") | |||
| print( | |||
| f"Is ArrayBooleanVariable: {isinstance(array_bool_var, ArrayBooleanVariable)}" | |||
| ) | |||
| # Test that bool comes before int (critical ordering) | |||
| print(f"\nTesting bool vs int precedence:") | |||
| print(f"True is instance of bool: {isinstance(True, bool)}") | |||
| print(f"True is instance of int: {isinstance(True, int)}") | |||
| print(f"False is instance of bool: {isinstance(False, bool)}") | |||
| print(f"False is instance of int: {isinstance(False, int)}") | |||
| # Verify that boolean values are correctly inferred as boolean, not int | |||
| assert true_segment.value_type == SegmentType.BOOLEAN, ( | |||
| "True should be inferred as BOOLEAN" | |||
| ) | |||
| assert false_segment.value_type == SegmentType.BOOLEAN, ( | |||
| "False should be inferred as BOOLEAN" | |||
| ) | |||
| assert bool_array_segment.value_type == SegmentType.ARRAY_BOOLEAN, ( | |||
| "Boolean array should be inferred as ARRAY_BOOLEAN" | |||
| ) | |||
| print("\n✅ All boolean inference tests passed!") | |||
| if __name__ == "__main__": | |||
| test_boolean_inference() | |||
| except ImportError as e: | |||
| print(f"Import error: {e}") | |||
| print("Make sure you're running this from the correct directory") | |||
| except Exception as e: | |||
| print(f"Error: {e}") | |||
| import traceback | |||
| traceback.print_exc() | |||
| @@ -1,230 +0,0 @@ | |||
| #!/usr/bin/env python3 | |||
| """ | |||
| Test script to verify boolean support in VariableAssigner node | |||
| """ | |||
| import sys | |||
| import os | |||
| # Add the api directory to the Python path | |||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "api")) | |||
| from core.variables import SegmentType | |||
| from core.workflow.nodes.variable_assigner.v2.helpers import ( | |||
| is_operation_supported, | |||
| is_constant_input_supported, | |||
| is_input_value_valid, | |||
| ) | |||
| from core.workflow.nodes.variable_assigner.v2.enums import Operation | |||
| from core.workflow.nodes.variable_assigner.v2.constants import EMPTY_VALUE_MAPPING | |||
| def test_boolean_operation_support(): | |||
| """Test that boolean types support the correct operations""" | |||
| print("Testing boolean operation support...") | |||
| # Boolean should support SET, OVER_WRITE, and CLEAR | |||
| assert is_operation_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.SET | |||
| ) | |||
| assert is_operation_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.OVER_WRITE | |||
| ) | |||
| assert is_operation_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.CLEAR | |||
| ) | |||
| # Boolean should NOT support arithmetic operations | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.ADD | |||
| ) | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.SUBTRACT | |||
| ) | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.MULTIPLY | |||
| ) | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.DIVIDE | |||
| ) | |||
| # Boolean should NOT support array operations | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.APPEND | |||
| ) | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.EXTEND | |||
| ) | |||
| print("✓ Boolean operation support tests passed") | |||
| def test_array_boolean_operation_support(): | |||
| """Test that array boolean types support the correct operations""" | |||
| print("Testing array boolean operation support...") | |||
| # Array boolean should support APPEND, EXTEND, SET, OVER_WRITE, CLEAR | |||
| assert is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.APPEND | |||
| ) | |||
| assert is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.EXTEND | |||
| ) | |||
| assert is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.OVER_WRITE | |||
| ) | |||
| assert is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.CLEAR | |||
| ) | |||
| assert is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.REMOVE_FIRST | |||
| ) | |||
| assert is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.REMOVE_LAST | |||
| ) | |||
| # Array boolean should NOT support arithmetic operations | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.ADD | |||
| ) | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.SUBTRACT | |||
| ) | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.MULTIPLY | |||
| ) | |||
| assert not is_operation_supported( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.DIVIDE | |||
| ) | |||
| print("✓ Array boolean operation support tests passed") | |||
| def test_boolean_constant_input_support(): | |||
| """Test that boolean types support constant input for correct operations""" | |||
| print("Testing boolean constant input support...") | |||
| # Boolean should support constant input for SET and OVER_WRITE | |||
| assert is_constant_input_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.SET | |||
| ) | |||
| assert is_constant_input_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.OVER_WRITE | |||
| ) | |||
| # Boolean should NOT support constant input for arithmetic operations | |||
| assert not is_constant_input_supported( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.ADD | |||
| ) | |||
| print("✓ Boolean constant input support tests passed") | |||
| def test_boolean_input_validation(): | |||
| """Test that boolean input validation works correctly""" | |||
| print("Testing boolean input validation...") | |||
| # Boolean values should be valid for boolean type | |||
| assert is_input_value_valid( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.SET, value=True | |||
| ) | |||
| assert is_input_value_valid( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.SET, value=False | |||
| ) | |||
| assert is_input_value_valid( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.OVER_WRITE, value=True | |||
| ) | |||
| # Non-boolean values should be invalid for boolean type | |||
| assert not is_input_value_valid( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.SET, value="true" | |||
| ) | |||
| assert not is_input_value_valid( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.SET, value=1 | |||
| ) | |||
| assert not is_input_value_valid( | |||
| variable_type=SegmentType.BOOLEAN, operation=Operation.SET, value=0 | |||
| ) | |||
| print("✓ Boolean input validation tests passed") | |||
| def test_array_boolean_input_validation(): | |||
| """Test that array boolean input validation works correctly""" | |||
| print("Testing array boolean input validation...") | |||
| # Boolean values should be valid for array boolean append | |||
| assert is_input_value_valid( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.APPEND, value=True | |||
| ) | |||
| assert is_input_value_valid( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, operation=Operation.APPEND, value=False | |||
| ) | |||
| # Boolean arrays should be valid for extend/overwrite | |||
| assert is_input_value_valid( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, | |||
| operation=Operation.EXTEND, | |||
| value=[True, False, True], | |||
| ) | |||
| assert is_input_value_valid( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, | |||
| operation=Operation.OVER_WRITE, | |||
| value=[False, False], | |||
| ) | |||
| # Non-boolean values should be invalid | |||
| assert not is_input_value_valid( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, | |||
| operation=Operation.APPEND, | |||
| value="true", | |||
| ) | |||
| assert not is_input_value_valid( | |||
| variable_type=SegmentType.ARRAY_BOOLEAN, | |||
| operation=Operation.EXTEND, | |||
| value=[True, "false"], | |||
| ) | |||
| print("✓ Array boolean input validation tests passed") | |||
| def test_empty_value_mapping(): | |||
| """Test that empty value mapping includes boolean types""" | |||
| print("Testing empty value mapping...") | |||
| # Check that boolean types have correct empty values | |||
| assert SegmentType.BOOLEAN in EMPTY_VALUE_MAPPING | |||
| assert EMPTY_VALUE_MAPPING[SegmentType.BOOLEAN] is False | |||
| assert SegmentType.ARRAY_BOOLEAN in EMPTY_VALUE_MAPPING | |||
| assert EMPTY_VALUE_MAPPING[SegmentType.ARRAY_BOOLEAN] == [] | |||
| print("✓ Empty value mapping tests passed") | |||
| def main(): | |||
| """Run all tests""" | |||
| print("Running VariableAssigner boolean support tests...\n") | |||
| try: | |||
| test_boolean_operation_support() | |||
| test_array_boolean_operation_support() | |||
| test_boolean_constant_input_support() | |||
| test_boolean_input_validation() | |||
| test_array_boolean_input_validation() | |||
| test_empty_value_mapping() | |||
| print( | |||
| "\n🎉 All tests passed! Boolean support has been successfully added to VariableAssigner." | |||
| ) | |||
| except Exception as e: | |||
| print(f"\n❌ Test failed: {e}") | |||
| import traceback | |||
| traceback.print_exc() | |||
| sys.exit(1) | |||
| if __name__ == "__main__": | |||
| main() | |||