forked from neuronaut73/langflow2langgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_all_graphs.py
More file actions
89 lines (69 loc) · 2.46 KB
/
test_all_graphs.py
File metadata and controls
89 lines (69 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Test All Converted Graphs
------------------------
This script tests all the converted LangGraph Python files in the output_graphs directory.
"""
import os
import sys
import importlib.util
import glob
def import_module_from_file(file_path):
"""Import a module from a file path."""
module_name = os.path.basename(file_path).replace(".py", "")
spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def test_graph(graph_file):
"""Test a single graph."""
try:
# Import the module
module = import_module_from_file(graph_file)
# Get the base filename without extension
base_name = os.path.basename(graph_file).replace(".py", "")
print(f"\n=== Testing {base_name} ===\n")
# Check if the module has a create_graph function
if not hasattr(module, "create_graph"):
print(f"Error: {base_name} does not have a create_graph function")
return False
# Create the graph
graph = module.create_graph()
# Test with a simple input
test_input = {
"input": f"Test input for {base_name}"
}
print("Input:", test_input)
print("\nProcessing...\n")
# Run the graph
result = graph.invoke(test_input)
print("Output:", result)
print("\nStatus: Success ✅")
return True
except Exception as e:
print(f"Error: {str(e)}")
print("\nStatus: Failed ❌")
return False
def main():
"""Main function to test all converted graphs."""
# Get all Python files in the output_graphs directory
graph_files = glob.glob("output_graphs/*.py")
if not graph_files:
print("No Python files found in output_graphs directory")
return 1
print(f"Found {len(graph_files)} graphs to test")
# Test each graph
success_count = 0
for graph_file in graph_files:
if test_graph(graph_file):
success_count += 1
print(f"\nTest Summary: {success_count}/{len(graph_files)} tests passed")
if success_count == len(graph_files):
print("\nAll tests passed! 🎉")
return 0
else:
print("\nSome tests failed. 😢")
return 1
if __name__ == "__main__":
sys.exit(main())