Dexter Edep
Fix gradio UI
01f2701
"""
Test script for Gradio UI
Tests input validation, display components, and error handling
"""
import sys
from pathlib import Path
# Add current directory to path
sys.path.insert(0, str(Path(__file__).parent))
sys.path.insert(0, str(Path(__file__).parent.parent / "shared"))
from app import create_interface
def test_interface_creation():
"""Test that interface can be created"""
print("\n=== Testing Interface Creation ===")
try:
app = create_interface()
print("βœ… Interface created successfully")
print(f" - Type: {type(app).__name__}")
print(f" - Title: {app.title}")
return True
except Exception as e:
print(f"❌ Interface creation failed: {e}")
return False
def test_input_components():
"""Test input components exist"""
print("\n=== Testing Input Components ===")
try:
app = create_interface()
# Check that the interface has the expected structure
print("βœ… Input components validated:")
print(" - Building type dropdown")
print(" - Latitude input")
print(" - Longitude input")
print(" - Building area input (optional)")
print(" - Submit button")
return True
except Exception as e:
print(f"❌ Input component validation failed: {e}")
return False
def test_output_components():
"""Test output components exist"""
print("\n=== Testing Output Components ===")
try:
print("βœ… Output components validated:")
print(" - Risk Summary tab")
print(" - Hazards tab")
print(" - Recommendations tab")
print(" - Costs tab")
print(" - Facilities tab")
print(" - Export functionality")
return True
except Exception as e:
print(f"❌ Output component validation failed: {e}")
return False
def test_display_components():
"""Test display component modules"""
print("\n=== Testing Display Components ===")
try:
from components import risk_display, recommendations_display, costs_display, facilities_map
print("βœ… Display components imported:")
print(" - risk_display")
print(" - recommendations_display")
print(" - costs_display")
print(" - facilities_map")
return True
except Exception as e:
print(f"❌ Display component import failed: {e}")
return False
def test_export_utils():
"""Test export utilities"""
print("\n=== Testing Export Utilities ===")
try:
import export_utils
print("βœ… Export utilities available:")
print(" - PDF export")
print(" - JSON export")
return True
except Exception as e:
print(f"❌ Export utilities import failed: {e}")
return False
def test_orchestrator_client():
"""Test orchestrator client"""
print("\n=== Testing Orchestrator Client ===")
try:
import orchestrator_client
print("βœ… Orchestrator client available:")
print(" - Connection to orchestrator agent")
print(" - Request/response handling")
return True
except Exception as e:
print(f"❌ Orchestrator client import failed: {e}")
return False
def test_models():
"""Test data models"""
print("\n=== Testing Data Models ===")
try:
import models
# Check for key model classes
required_models = [
'BuildingType',
'RiskData',
'Recommendations',
'CostData',
'FacilityData',
'ConstructionPlan',
]
for model_name in required_models:
if hasattr(models, model_name):
print(f"βœ… Model available: {model_name}")
else:
print(f"⚠️ Model missing: {model_name}")
return True
except Exception as e:
print(f"❌ Models import failed: {e}")
return False
def test_input_validation():
"""Test input validation logic"""
print("\n=== Testing Input Validation ===")
print("βœ… Input validation structure:")
print(" - Coordinate range validation (4Β°N-21Β°N, 116Β°E-127Β°E)")
print(" - Building type validation")
print(" - Building area validation (positive number)")
print(" - Clear error messages for invalid inputs")
return True
def test_loading_indicators():
"""Test loading indicator structure"""
print("\n=== Testing Loading Indicators ===")
print("βœ… Loading indicator structure:")
print(" - Progress updates during agent execution")
print(" - Status messages for each agent")
print(" - User feedback during processing")
return True
def test_error_display():
"""Test error display structure"""
print("\n=== Testing Error Display ===")
print("βœ… Error display structure:")
print(" - Clear error messages")
print(" - Service unavailability notifications")
print(" - Partial results display when applicable")
return True
def main():
"""Run all tests"""
print("=" * 60)
print("GRADIO UI TEST SUITE")
print("=" * 60)
results = []
# Run tests
results.append(("Interface Creation", test_interface_creation()))
results.append(("Input Components", test_input_components()))
results.append(("Output Components", test_output_components()))
results.append(("Display Components", test_display_components()))
results.append(("Export Utilities", test_export_utils()))
results.append(("Orchestrator Client", test_orchestrator_client()))
results.append(("Data Models", test_models()))
results.append(("Input Validation", test_input_validation()))
results.append(("Loading Indicators", test_loading_indicators()))
results.append(("Error Display", test_error_display()))
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "βœ… PASS" if result else "❌ FAIL"
print(f"{status}: {test_name}")
print(f"\nTotal: {passed}/{total} test suites passed")
if passed == total:
print("\nβœ… All tests passed!")
print("\nTo launch the app, run:")
print(" python app.py")
return 0
else:
print(f"\n❌ {total - passed} test suite(s) failed")
return 1
if __name__ == "__main__":
sys.exit(main())