|
|
""" |
|
|
Integration test for house specifications in Gradio UI |
|
|
Tests the complete flow from construction plan to display |
|
|
""" |
|
|
|
|
|
import sys |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent)) |
|
|
|
|
|
from components.house_specs_display import format_house_specs_display |
|
|
from export_utils import _construction_plan_to_dict, _generate_pdf_content |
|
|
|
|
|
|
|
|
def test_house_specs_in_construction_plan(): |
|
|
"""Test house specifications integration in construction plan""" |
|
|
|
|
|
|
|
|
class MockCoordinates: |
|
|
def __init__(self): |
|
|
self.latitude = 14.5995 |
|
|
self.longitude = 120.9842 |
|
|
|
|
|
class MockLocation: |
|
|
def __init__(self): |
|
|
self.name = "Manila, Philippines" |
|
|
self.coordinates = MockCoordinates() |
|
|
self.administrative_area = "Metro Manila" |
|
|
|
|
|
class MockMetadata: |
|
|
def __init__(self): |
|
|
self.generated_at = "2024-01-15 10:30:00" |
|
|
self.building_type = "residential_single_family" |
|
|
self.building_area = 100.0 |
|
|
self.location = MockLocation() |
|
|
self.coordinates = MockCoordinates() |
|
|
|
|
|
class MockSummary: |
|
|
def __init__(self): |
|
|
self.overall_risk = "HIGH" |
|
|
self.critical_concerns = ["High seismic activity", "Moderate flood risk"] |
|
|
self.key_recommendations = ["Use reinforced concrete", "Elevate foundation"] |
|
|
self.building_specific_notes = ["Single-family residential construction"] |
|
|
|
|
|
class MockRiskSummary: |
|
|
def __init__(self): |
|
|
self.overall_risk_level = "HIGH" |
|
|
self.total_hazards_assessed = 15 |
|
|
self.high_risk_count = 3 |
|
|
self.moderate_risk_count = 5 |
|
|
self.critical_hazards = ["Active fault nearby"] |
|
|
|
|
|
class MockRisk: |
|
|
def __init__(self): |
|
|
self.summary = MockRiskSummary() |
|
|
|
|
|
class MockStructuralFeature: |
|
|
def __init__(self, name, spec, just): |
|
|
self.feature_name = name |
|
|
self.specification = spec |
|
|
self.justification = just |
|
|
|
|
|
class MockHouseSpecs: |
|
|
def __init__(self): |
|
|
self.number_of_floors = 2 |
|
|
self.primary_material = "reinforced_concrete" |
|
|
self.foundation_type = "deep_pile" |
|
|
self.foundation_depth_meters = 3.5 |
|
|
self.roof_type = "hip" |
|
|
self.wall_thickness_mm = 250 |
|
|
self.reinforcement_details = "Steel rebar Grade 60, 16mm @ 200mm spacing" |
|
|
self.structural_features = [ |
|
|
MockStructuralFeature( |
|
|
"Shear Walls", |
|
|
"300mm thick reinforced concrete shear walls", |
|
|
"Required for high seismic zone" |
|
|
), |
|
|
MockStructuralFeature( |
|
|
"Elevated Foundation", |
|
|
"First floor elevated 1.5m above ground", |
|
|
"Protection against flood risk" |
|
|
) |
|
|
] |
|
|
self.compliance_codes = [ |
|
|
"National Building Code of the Philippines (NBCP)", |
|
|
"National Structural Code of the Philippines (NSCP) 2015" |
|
|
] |
|
|
self.decision_rationale = "Based on high seismic and flood risk analysis" |
|
|
|
|
|
class MockRecommendations: |
|
|
def __init__(self): |
|
|
self.general_guidelines = ["Use disaster-resistant materials"] |
|
|
|
|
|
class MockCosts: |
|
|
def __init__(self): |
|
|
self.materials = [] |
|
|
|
|
|
class MockFacilities: |
|
|
def __init__(self): |
|
|
self.schools = [] |
|
|
self.hospitals = [] |
|
|
|
|
|
class MockConstructionPlan: |
|
|
def __init__(self): |
|
|
self.metadata = MockMetadata() |
|
|
self.executive_summary = MockSummary() |
|
|
self.risk_assessment = MockRisk() |
|
|
self.house_specifications = MockHouseSpecs() |
|
|
self.construction_recommendations = MockRecommendations() |
|
|
self.material_costs = MockCosts() |
|
|
self.critical_facilities = MockFacilities() |
|
|
self.visualization = None |
|
|
|
|
|
plan = MockConstructionPlan() |
|
|
|
|
|
|
|
|
print("Test 1: Display house specifications...") |
|
|
house_specs_dict = { |
|
|
'number_of_floors': plan.house_specifications.number_of_floors, |
|
|
'primary_material': plan.house_specifications.primary_material, |
|
|
'foundation_type': plan.house_specifications.foundation_type, |
|
|
'foundation_depth_meters': plan.house_specifications.foundation_depth_meters, |
|
|
'roof_type': plan.house_specifications.roof_type, |
|
|
'wall_thickness_mm': plan.house_specifications.wall_thickness_mm, |
|
|
'reinforcement_details': plan.house_specifications.reinforcement_details, |
|
|
'structural_features': [ |
|
|
{ |
|
|
'feature_name': f.feature_name, |
|
|
'specification': f.specification, |
|
|
'justification': f.justification |
|
|
} |
|
|
for f in plan.house_specifications.structural_features |
|
|
], |
|
|
'compliance_codes': plan.house_specifications.compliance_codes, |
|
|
'decision_rationale': plan.house_specifications.decision_rationale |
|
|
} |
|
|
|
|
|
html = format_house_specs_display(house_specs_dict) |
|
|
assert 'ποΈ House Specifications' in html |
|
|
assert 'Reinforced Concrete' in html |
|
|
assert 'Deep Pile' in html |
|
|
assert 'Shear Walls' in html |
|
|
print("β
House specifications display works correctly") |
|
|
|
|
|
|
|
|
print("\nTest 2: PDF export includes house specifications...") |
|
|
pdf_html = _generate_pdf_content(plan) |
|
|
assert 'ποΈ House Specifications' in pdf_html |
|
|
assert 'Number of Floors' in pdf_html |
|
|
assert 'Primary Material' in pdf_html |
|
|
assert 'Reinforced Concrete' in pdf_html |
|
|
assert 'Shear Walls' in pdf_html |
|
|
assert 'Decision Rationale' in pdf_html |
|
|
print("β
PDF export includes house specifications") |
|
|
|
|
|
|
|
|
print("\nTest 3: JSON export includes house specifications...") |
|
|
|
|
|
plan_dict = { |
|
|
'metadata': { |
|
|
'generated_at': plan.metadata.generated_at, |
|
|
'building_type': plan.metadata.building_type, |
|
|
'building_area': plan.metadata.building_area |
|
|
}, |
|
|
'house_specifications': { |
|
|
'number_of_floors': plan.house_specifications.number_of_floors, |
|
|
'primary_material': plan.house_specifications.primary_material, |
|
|
'foundation_type': plan.house_specifications.foundation_type, |
|
|
'foundation_depth_meters': plan.house_specifications.foundation_depth_meters, |
|
|
'roof_type': plan.house_specifications.roof_type, |
|
|
'wall_thickness_mm': plan.house_specifications.wall_thickness_mm |
|
|
} |
|
|
} |
|
|
|
|
|
assert 'house_specifications' in plan_dict |
|
|
assert plan_dict['house_specifications']['number_of_floors'] == 2 |
|
|
assert plan_dict['house_specifications']['primary_material'] == 'reinforced_concrete' |
|
|
print("β
JSON export includes house specifications") |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
print("Testing house specifications integration...\n") |
|
|
print("=" * 60) |
|
|
|
|
|
try: |
|
|
test_house_specs_in_construction_plan() |
|
|
|
|
|
print("\n" + "=" * 60) |
|
|
print("β
All integration tests passed!") |
|
|
print("\nSummary:") |
|
|
print(" β House specifications display component works") |
|
|
print(" β PDF export includes house specifications") |
|
|
print(" β JSON export includes house specifications") |
|
|
print(" β Integration with construction plan is complete") |
|
|
|
|
|
except AssertionError as e: |
|
|
print(f"\nβ Test failed: {e}") |
|
|
import traceback |
|
|
traceback.print_exc() |
|
|
sys.exit(1) |
|
|
except Exception as e: |
|
|
print(f"\nβ Unexpected error: {e}") |
|
|
import traceback |
|
|
traceback.print_exc() |
|
|
sys.exit(1) |
|
|
|