|
|
""" |
|
|
Integration test for visualization display in Gradio app |
|
|
""" |
|
|
|
|
|
import sys |
|
|
import os |
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
|
|
|
|
|
from components import format_visualization_display |
|
|
|
|
|
|
|
|
def test_visualization_import(): |
|
|
"""Test that visualization display can be imported""" |
|
|
assert format_visualization_display is not None |
|
|
print("β
Test passed: visualization display import") |
|
|
|
|
|
|
|
|
def test_visualization_in_components(): |
|
|
"""Test that visualization display is in components __all__""" |
|
|
from components import __all__ |
|
|
assert 'format_visualization_display' in __all__ |
|
|
print("β
Test passed: visualization display in components __all__") |
|
|
|
|
|
|
|
|
def test_app_imports(): |
|
|
"""Test that app.py can import visualization display""" |
|
|
try: |
|
|
|
|
|
import app |
|
|
print("β
Test passed: app.py imports successfully") |
|
|
except Exception as e: |
|
|
print(f"β Test failed: app.py import error: {e}") |
|
|
raise |
|
|
|
|
|
|
|
|
def test_mock_construction_plan_with_visualization(): |
|
|
"""Test processing a mock construction plan with visualization data""" |
|
|
|
|
|
png_base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==" |
|
|
|
|
|
mock_construction_plan = { |
|
|
'metadata': { |
|
|
'building_type': 'residential_single_family', |
|
|
'location': {'name': 'Manila'}, |
|
|
'coordinates': {'latitude': 14.5995, 'longitude': 120.9842}, |
|
|
'building_area': 100, |
|
|
'generated_at': '2024-01-01T12:00:00Z' |
|
|
}, |
|
|
'executive_summary': { |
|
|
'overall_risk': 'HIGH', |
|
|
'critical_concerns': ['Seismic risk'], |
|
|
'key_recommendations': ['Use reinforced concrete'], |
|
|
'building_specific_notes': [] |
|
|
}, |
|
|
'risk_assessment': { |
|
|
'success': True, |
|
|
'summary': { |
|
|
'overall_risk_level': 'HIGH', |
|
|
'total_hazards_assessed': 5, |
|
|
'high_risk_count': 2, |
|
|
'moderate_risk_count': 1, |
|
|
'critical_hazards': ['Active fault'] |
|
|
}, |
|
|
'location': { |
|
|
'name': 'Manila', |
|
|
'coordinates': {'latitude': 14.5995, 'longitude': 120.9842}, |
|
|
'administrative_area': 'Metro Manila' |
|
|
}, |
|
|
'hazards': {}, |
|
|
'facilities': {}, |
|
|
'metadata': {} |
|
|
}, |
|
|
'construction_recommendations': {}, |
|
|
'material_costs': {}, |
|
|
'critical_facilities': {}, |
|
|
'export_formats': {}, |
|
|
'visualization': { |
|
|
'image_base64': png_base64, |
|
|
'prompt_used': 'Single-family home in Manila with seismic reinforcement', |
|
|
'model_version': 'gemini-2.5-flash-image', |
|
|
'generation_timestamp': '2024-01-01T12:00:00Z', |
|
|
'image_format': 'PNG', |
|
|
'resolution': '1024x1024', |
|
|
'features_included': [ |
|
|
'Reinforced concrete frame', |
|
|
'Seismic cross-bracing', |
|
|
'Deep pile foundation' |
|
|
] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
visualization = mock_construction_plan.get('visualization', {}) |
|
|
html, image_path, download_path = format_visualization_display(visualization) |
|
|
|
|
|
assert html is not None |
|
|
assert 'π¨ Architectural Visualization' in html |
|
|
assert 'gemini-2.5-flash-image' in html |
|
|
assert 'Reinforced concrete frame' in html |
|
|
assert image_path is not None |
|
|
assert os.path.exists(image_path) |
|
|
assert download_path is not None |
|
|
assert os.path.exists(download_path) |
|
|
|
|
|
|
|
|
if image_path and os.path.exists(image_path): |
|
|
os.remove(image_path) |
|
|
if download_path and os.path.exists(download_path): |
|
|
os.remove(download_path) |
|
|
|
|
|
print("β
Test passed: mock construction plan with visualization") |
|
|
|
|
|
|
|
|
def test_mock_construction_plan_without_visualization(): |
|
|
"""Test processing a mock construction plan without visualization data""" |
|
|
mock_construction_plan = { |
|
|
'metadata': {}, |
|
|
'executive_summary': {}, |
|
|
'risk_assessment': {}, |
|
|
'construction_recommendations': {}, |
|
|
'material_costs': {}, |
|
|
'critical_facilities': {}, |
|
|
'export_formats': {} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
visualization = mock_construction_plan.get('visualization', {}) |
|
|
html, image_path, download_path = format_visualization_display(visualization) |
|
|
|
|
|
assert html is not None |
|
|
assert 'No Visualization Available' in html |
|
|
assert image_path is None |
|
|
assert download_path is None |
|
|
|
|
|
print("β
Test passed: mock construction plan without visualization") |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
print("Running visualization integration tests...\n") |
|
|
|
|
|
test_visualization_import() |
|
|
test_visualization_in_components() |
|
|
test_app_imports() |
|
|
test_mock_construction_plan_with_visualization() |
|
|
test_mock_construction_plan_without_visualization() |
|
|
|
|
|
print("\nβ
All integration tests passed!") |
|
|
|