🧪 test(process.py): add tests for process_tweaks function
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.
This commit is contained in:
parent
7817c64591
commit
bcf0b88a7c
1 changed files with 196 additions and 0 deletions
196
tests/test_process.py
Normal file
196
tests/test_process.py
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue