214 lines
7.7 KiB
Python
214 lines
7.7 KiB
Python
"""
|
|
Test main mesh processing workflow
|
|
"""
|
|
import pytest
|
|
import os
|
|
import time
|
|
from backend.utils.mesh_processor import process_blade_mesh, process_blade_mesh_with_state_updates, ProcessingStep, MeshProcessingResult
|
|
|
|
|
|
def test_mesh_processing_simulation():
|
|
"""Test complete mesh processing workflow in simulation mode"""
|
|
# Use the real test file from resource directory
|
|
test_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resource", "blade.step")
|
|
|
|
# Verify test file exists
|
|
assert os.path.exists(test_file), f"Test file not found: {test_file}"
|
|
|
|
# Track progress updates
|
|
progress_updates = []
|
|
|
|
def progress_callback(percentage, message, step):
|
|
progress_updates.append({
|
|
'percentage': percentage,
|
|
'message': message,
|
|
'step': step.value
|
|
})
|
|
print(f"Progress: {percentage:.1f}% - {message} ({step.value})")
|
|
|
|
# Process mesh in simulation mode
|
|
result = process_blade_mesh(
|
|
file_path=test_file,
|
|
progress_callback=progress_callback,
|
|
simulation_mode=True
|
|
)
|
|
|
|
# Verify result structure
|
|
assert isinstance(result, MeshProcessingResult)
|
|
assert result.started_at is not None
|
|
assert result.completed_at is not None
|
|
assert result.total_time > 0
|
|
|
|
# Verify successful processing
|
|
assert result.success is True
|
|
assert result.current_step == ProcessingStep.COMPLETED
|
|
assert result.progress_percentage == 100.0
|
|
assert result.error_message is None
|
|
|
|
# Verify mesh data
|
|
assert result.element_count > 0
|
|
assert result.node_count > 0
|
|
assert result.quality_score >= 0.0
|
|
assert result.quality_status in ["PASSED", "FAILED"]
|
|
|
|
# Verify step results exist
|
|
assert result.geometry_result is not None
|
|
assert result.named_selections_result is not None
|
|
assert result.mesh_controls_result is not None
|
|
assert result.mesh_generation_result is not None
|
|
assert result.quality_check_result is not None
|
|
|
|
# Verify progress tracking
|
|
assert len(progress_updates) >= 8 # Should have multiple progress updates
|
|
assert progress_updates[0]['percentage'] <= progress_updates[-1]['percentage'] # Progress should increase
|
|
assert progress_updates[-1]['percentage'] == 100.0 # Should end at 100%
|
|
|
|
# Verify all major steps were covered
|
|
steps_covered = [update['step'] for update in progress_updates]
|
|
expected_steps = [
|
|
'starting_session', 'importing_geometry', 'validating_geometry',
|
|
'creating_named_selections', 'applying_mesh_controls',
|
|
'generating_mesh', 'checking_quality', 'completed'
|
|
]
|
|
for expected_step in expected_steps:
|
|
assert expected_step in steps_covered
|
|
|
|
print(f"✓ Mesh processing completed successfully:")
|
|
print(f" - Total time: {result.total_time:.1f} seconds")
|
|
print(f" - Elements: {result.element_count}")
|
|
print(f" - Nodes: {result.node_count}")
|
|
print(f" - Quality score: {result.quality_score:.1f}")
|
|
print(f" - Quality status: {result.quality_status}")
|
|
print(f" - Progress updates: {len(progress_updates)}")
|
|
print(f" - Warnings: {len(result.warnings)}")
|
|
|
|
|
|
def test_mesh_processing_with_state_updates():
|
|
"""Test mesh processing with state manager integration"""
|
|
from backend.utils.state_manager import state_manager
|
|
|
|
# Clear any existing state
|
|
state_manager.clear_session_data()
|
|
|
|
# Use the real test file from resource directory
|
|
test_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resource", "blade.step")
|
|
|
|
# Verify test file exists
|
|
assert os.path.exists(test_file), f"Test file not found: {test_file}"
|
|
|
|
# Process mesh with state updates
|
|
result = process_blade_mesh_with_state_updates(
|
|
file_path=test_file,
|
|
simulation_mode=True
|
|
)
|
|
|
|
# Verify processing result
|
|
assert result.success is True
|
|
assert result.element_count > 0
|
|
assert result.node_count > 0
|
|
|
|
# Verify state manager was updated
|
|
processing_status = state_manager.get_processing_status()
|
|
assert processing_status.status == "completed"
|
|
assert processing_status.progress_percentage == 100.0
|
|
assert processing_status.completed_at is not None
|
|
|
|
# Verify mesh result was stored
|
|
mesh_result = state_manager.get_mesh_result()
|
|
assert mesh_result is not None
|
|
assert mesh_result.element_count == result.element_count
|
|
assert mesh_result.node_count == result.node_count
|
|
assert mesh_result.quality_score == result.quality_score
|
|
assert mesh_result.quality_status == result.quality_status
|
|
|
|
print(f"✓ State manager integration test passed:")
|
|
print(f" - Processing status: {processing_status.status}")
|
|
print(f" - Mesh elements: {mesh_result.element_count}")
|
|
print(f" - Mesh nodes: {mesh_result.node_count}")
|
|
print(f" - Quality score: {mesh_result.quality_score:.1f}")
|
|
|
|
|
|
def test_mesh_processing_error_handling():
|
|
"""Test error handling in mesh processing"""
|
|
# Test with invalid file path to trigger error
|
|
invalid_file = "nonexistent_file.step"
|
|
|
|
# Process mesh (should fail gracefully)
|
|
result = process_blade_mesh(
|
|
file_path=invalid_file,
|
|
simulation_mode=True # Still use simulation mode
|
|
)
|
|
|
|
# Verify failure handling
|
|
assert result.success is False
|
|
assert result.current_step == ProcessingStep.FAILED
|
|
assert result.error_message is not None
|
|
assert result.completed_at is not None
|
|
assert result.total_time >= 0
|
|
|
|
print(f"✓ Error handling test passed:")
|
|
print(f" - Failed as expected: {result.error_message}")
|
|
print(f" - Processing time: {result.total_time:.1f} seconds")
|
|
|
|
|
|
def test_processing_steps_enum():
|
|
"""Test processing steps enumeration"""
|
|
# Verify all expected steps exist
|
|
expected_steps = [
|
|
'INITIALIZING', 'STARTING_SESSION', 'IMPORTING_GEOMETRY',
|
|
'VALIDATING_GEOMETRY', 'CREATING_NAMED_SELECTIONS',
|
|
'APPLYING_MESH_CONTROLS', 'GENERATING_MESH',
|
|
'CHECKING_QUALITY', 'FINALIZING', 'COMPLETED', 'FAILED'
|
|
]
|
|
|
|
for step_name in expected_steps:
|
|
assert hasattr(ProcessingStep, step_name)
|
|
step = getattr(ProcessingStep, step_name)
|
|
assert isinstance(step.value, str)
|
|
|
|
print(f"✓ Processing steps enum test passed: {len(expected_steps)} steps defined")
|
|
|
|
|
|
def test_mesh_processing_result_structure():
|
|
"""Test MeshProcessingResult data structure"""
|
|
result = MeshProcessingResult()
|
|
|
|
# Verify initial state
|
|
assert result.success is False
|
|
assert result.current_step == ProcessingStep.INITIALIZING
|
|
assert result.progress_percentage == 0.0
|
|
assert result.element_count == 0
|
|
assert result.node_count == 0
|
|
assert result.quality_score == 0.0
|
|
assert result.quality_status == "UNKNOWN"
|
|
assert isinstance(result.warnings, list)
|
|
|
|
# Verify all result containers exist
|
|
assert result.geometry_result is None
|
|
assert result.named_selections_result is None
|
|
assert result.mesh_controls_result is None
|
|
assert result.mesh_generation_result is None
|
|
assert result.quality_check_result is None
|
|
|
|
print("✓ MeshProcessingResult structure test passed")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("Testing Main Mesh Processing Workflow...")
|
|
|
|
test_processing_steps_enum()
|
|
print("✓ Processing steps enum test passed")
|
|
|
|
test_mesh_processing_result_structure()
|
|
print("✓ Result structure test passed")
|
|
|
|
test_mesh_processing_simulation()
|
|
print("✓ Simulation processing test passed")
|
|
|
|
test_mesh_processing_with_state_updates()
|
|
print("✓ State updates test passed")
|
|
|
|
test_mesh_processing_error_handling()
|
|
print("✓ Error handling test passed")
|
|
|
|
print("\n🎉 All mesh processing workflow tests passed!") |