Spaces:
No application file
No application file
File size: 5,333 Bytes
92ef79b |
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
#!/usr/bin/env python3
"""
Test script for DAG visualization functionality
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from dag_visualizer import DAGVisualizer
import json
def test_single_task():
"""Test with a single task (no dependencies)"""
print("Testing single task visualization...")
task_data = {
"tasks": [
{
"task": "target_area_for_specific_robots_1",
"instruction_function": {
"name": "target_area_for_specific_robots",
"robot_ids": ["robot_dump_truck_01"],
"dependencies": [],
"object_keywords": ["puddle1"]
}
}
]
}
visualizer = DAGVisualizer()
image_path = visualizer.create_dag_visualization(task_data)
if image_path and os.path.exists(image_path):
print(f"β Single task visualization created: {image_path}")
return True
else:
print("β Failed to create single task visualization")
return False
def test_multiple_tasks_with_dependencies():
"""Test with multiple tasks with dependencies"""
print("Testing multiple tasks with dependencies...")
task_data = {
"tasks": [
{
"task": "target_area_for_specific_robots_1",
"instruction_function": {
"name": "target_area_for_specific_robots",
"robot_ids": ["robot_dump_truck_01"],
"dependencies": [],
"object_keywords": ["puddle1"]
}
},
{
"task": "avoid_areas_for_all_robots_1",
"instruction_function": {
"name": "avoid_areas_for_all_robots",
"robot_ids": ["robot_dump_truck_01", "robot_excavator_01"],
"dependencies": ["target_area_for_specific_robots_1"],
"object_keywords": ["obstacle1", "obstacle2"]
}
},
{
"task": "move_to_position_1",
"instruction_function": {
"name": "move_to_position",
"robot_ids": ["robot_excavator_01"],
"dependencies": ["avoid_areas_for_all_robots_1"],
"object_keywords": ["soil_pile"]
}
}
]
}
visualizer = DAGVisualizer()
image_path = visualizer.create_dag_visualization(task_data)
if image_path and os.path.exists(image_path):
print(f"β Multiple tasks visualization created: {image_path}")
return True
else:
print("β Failed to create multiple tasks visualization")
return False
def test_simplified_visualization():
"""Test simplified visualization"""
print("Testing simplified visualization...")
task_data = {
"tasks": [
{
"task": "excavate_soil_from_pile",
"instruction_function": {
"name": "excavate_soil_from_pile",
"robot_ids": ["robot_excavator_01"],
"dependencies": [],
"object_keywords": ["soil_pile"]
}
},
{
"task": "transport_soil_to_pit",
"instruction_function": {
"name": "transport_soil_to_pit",
"robot_ids": ["robot_dump_truck_01"],
"dependencies": ["excavate_soil_from_pile"],
"object_keywords": ["pit"]
}
}
]
}
visualizer = DAGVisualizer()
image_path = visualizer.create_simplified_dag_visualization(task_data)
if image_path and os.path.exists(image_path):
print(f"β Simplified visualization created: {image_path}")
return True
else:
print("β Failed to create simplified visualization")
return False
def test_invalid_data():
"""Test with invalid data"""
print("Testing invalid data handling...")
# Test with empty data
visualizer = DAGVisualizer()
image_path = visualizer.create_dag_visualization({})
if image_path is None:
print("β Invalid data handled correctly (returned None)")
return True
else:
print("β Invalid data not handled correctly")
return False
def main():
"""Run all tests"""
print("Starting DAG Visualization Tests...")
print("=" * 50)
tests = [
test_single_task,
test_multiple_tasks_with_dependencies,
test_simplified_visualization,
test_invalid_data
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
print()
except Exception as e:
print(f"β Test failed with exception: {e}")
print()
print("=" * 50)
print(f"Tests passed: {passed}/{total}")
if passed == total:
print("π All tests passed!")
return True
else:
print("β Some tests failed!")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |