|
|
""" |
|
|
Test script for Gradio UI |
|
|
Tests input validation, display components, and error handling |
|
|
""" |
|
|
import sys |
|
|
from pathlib import 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() |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 = [] |
|
|
|
|
|
|
|
|
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())) |
|
|
|
|
|
|
|
|
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()) |
|
|
|