|
| 1 | +import pytest |
| 2 | +from comfy_execution.validation import validate_node_input |
| 3 | + |
| 4 | + |
| 5 | +def test_exact_match(): |
| 6 | + """Test cases where types match exactly""" |
| 7 | + assert validate_node_input("STRING", "STRING") |
| 8 | + assert validate_node_input("STRING,INT", "STRING,INT") |
| 9 | + assert ( |
| 10 | + validate_node_input("INT,STRING", "STRING,INT") |
| 11 | + ) # Order shouldn't matter |
| 12 | + |
| 13 | + |
| 14 | +def test_strict_mode(): |
| 15 | + """Test strict mode validation""" |
| 16 | + # Should pass - received type is subset of input type |
| 17 | + assert validate_node_input("STRING", "STRING,INT", strict=True) |
| 18 | + assert validate_node_input("INT", "STRING,INT", strict=True) |
| 19 | + assert validate_node_input("STRING,INT", "STRING,INT,BOOLEAN", strict=True) |
| 20 | + |
| 21 | + # Should fail - received type is not subset of input type |
| 22 | + assert not validate_node_input("STRING,INT", "STRING", strict=True) |
| 23 | + assert not validate_node_input("STRING,BOOLEAN", "STRING", strict=True) |
| 24 | + assert not validate_node_input("INT,BOOLEAN", "STRING,INT", strict=True) |
| 25 | + |
| 26 | + |
| 27 | +def test_non_strict_mode(): |
| 28 | + """Test non-strict mode validation (default behavior)""" |
| 29 | + # Should pass - types have overlap |
| 30 | + assert validate_node_input("STRING,BOOLEAN", "STRING,INT") |
| 31 | + assert validate_node_input("STRING,INT", "INT,BOOLEAN") |
| 32 | + assert validate_node_input("STRING", "STRING,INT") |
| 33 | + |
| 34 | + # Should fail - no overlap in types |
| 35 | + assert not validate_node_input("BOOLEAN", "STRING,INT") |
| 36 | + assert not validate_node_input("FLOAT", "STRING,INT") |
| 37 | + assert not validate_node_input("FLOAT,BOOLEAN", "STRING,INT") |
| 38 | + |
| 39 | + |
| 40 | +def test_whitespace_handling(): |
| 41 | + """Test that whitespace is handled correctly""" |
| 42 | + assert validate_node_input("STRING, INT", "STRING,INT") |
| 43 | + assert validate_node_input("STRING,INT", "STRING, INT") |
| 44 | + assert validate_node_input(" STRING , INT ", "STRING,INT") |
| 45 | + assert validate_node_input("STRING,INT", " STRING , INT ") |
| 46 | + |
| 47 | + |
| 48 | +def test_empty_strings(): |
| 49 | + """Test behavior with empty strings""" |
| 50 | + assert validate_node_input("", "") |
| 51 | + assert not validate_node_input("STRING", "") |
| 52 | + assert not validate_node_input("", "STRING") |
| 53 | + |
| 54 | + |
| 55 | +def test_single_vs_multiple(): |
| 56 | + """Test single type against multiple types""" |
| 57 | + assert validate_node_input("STRING", "STRING,INT,BOOLEAN") |
| 58 | + assert validate_node_input("STRING,INT,BOOLEAN", "STRING", strict=False) |
| 59 | + assert not validate_node_input("STRING,INT,BOOLEAN", "STRING", strict=True) |
| 60 | + |
| 61 | + |
| 62 | +@pytest.mark.parametrize( |
| 63 | + "received,input_type,strict,expected", |
| 64 | + [ |
| 65 | + ("STRING", "STRING", False, True), |
| 66 | + ("STRING,INT", "STRING,INT", False, True), |
| 67 | + ("STRING", "STRING,INT", True, True), |
| 68 | + ("STRING,INT", "STRING", True, False), |
| 69 | + ("BOOLEAN", "STRING,INT", False, False), |
| 70 | + ("STRING,BOOLEAN", "STRING,INT", False, True), |
| 71 | + ], |
| 72 | +) |
| 73 | +def test_parametrized_cases(received, input_type, strict, expected): |
| 74 | + """Parametrized test cases for various scenarios""" |
| 75 | + assert validate_node_input(received, input_type, strict) == expected |
0 commit comments