This commit adds tests for the process_tweaks function in the langflow.processing.process module. The tests cover the following scenarios: - No tweaks are applied to the graph data - A single tweak is applied to the graph data - Multiple tweaks are applied to the graph data - A tweak is applied to a non-existent parameter in the graph data The tests ensure that the function processes the tweaks correctly and returns the expected result.
196 lines
5.5 KiB
Python
196 lines
5.5 KiB
Python
from langflow.processing.process import process_tweaks
|
|
|
|
|
|
def test_no_tweaks():
|
|
graph_data = {
|
|
"data": {
|
|
"nodes": [
|
|
{
|
|
"id": "node1",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 1},
|
|
"param2": {"value": 2},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
"id": "node2",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 3},
|
|
"param2": {"value": 4},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
]
|
|
}
|
|
}
|
|
tweaks = {}
|
|
result = process_tweaks(graph_data, tweaks)
|
|
assert result == graph_data
|
|
|
|
|
|
def test_single_tweak():
|
|
graph_data = {
|
|
"data": {
|
|
"nodes": [
|
|
{
|
|
"id": "node1",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 1},
|
|
"param2": {"value": 2},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
"id": "node2",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 3},
|
|
"param2": {"value": 4},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
]
|
|
}
|
|
}
|
|
tweaks = {"node1": {"param1": 5}}
|
|
expected_result = {
|
|
"data": {
|
|
"nodes": [
|
|
{
|
|
"id": "node1",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 5},
|
|
"param2": {"value": 2},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
"id": "node2",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 3},
|
|
"param2": {"value": 4},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
]
|
|
}
|
|
}
|
|
result = process_tweaks(graph_data, tweaks)
|
|
assert result == expected_result
|
|
|
|
|
|
def test_multiple_tweaks():
|
|
graph_data = {
|
|
"data": {
|
|
"nodes": [
|
|
{
|
|
"id": "node1",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 1},
|
|
"param2": {"value": 2},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
"id": "node2",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 3},
|
|
"param2": {"value": 4},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
]
|
|
}
|
|
}
|
|
tweaks = {
|
|
"node1": {"param1": 5, "param2": 6},
|
|
"node2": {"param1": 7},
|
|
}
|
|
expected_result = {
|
|
"data": {
|
|
"nodes": [
|
|
{
|
|
"id": "node1",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 5},
|
|
"param2": {"value": 6},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
"id": "node2",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 7},
|
|
"param2": {"value": 4},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
]
|
|
}
|
|
}
|
|
result = process_tweaks(graph_data, tweaks)
|
|
assert result == expected_result
|
|
|
|
|
|
def test_tweak_not_in_template():
|
|
graph_data = {
|
|
"data": {
|
|
"nodes": [
|
|
{
|
|
"id": "node1",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 1},
|
|
"param2": {"value": 2},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
"id": "node2",
|
|
"data": {
|
|
"node": {
|
|
"template": {
|
|
"param1": {"value": 3},
|
|
"param2": {"value": 4},
|
|
}
|
|
}
|
|
},
|
|
},
|
|
]
|
|
}
|
|
}
|
|
tweaks = {"node1": {"param3": 5}}
|
|
result = process_tweaks(graph_data, tweaks)
|
|
assert result == graph_data
|