| |
| """ |
| Test the Processing Queue Implementation |
| Quick test to verify the processing queue interface works |
| """ |
|
|
| import sys |
| import os |
| sys.path.append(os.path.join(os.path.dirname(__file__), 'src')) |
|
|
| def test_processing_queue(): |
| """Test the processing queue functionality""" |
| print("π§ͺ Testing Processing Queue Implementation...") |
| |
| try: |
| |
| from frontend_ui import ProcessingQueue, ProcessingJob, processing_queue |
| print("β
Successfully imported processing queue components") |
| |
| |
| assert len(processing_queue.jobs) > 0, "Queue should have demo data" |
| print(f"β
Queue initialized with {len(processing_queue.jobs)} demo jobs") |
| |
| |
| test_job = processing_queue.add_job("test_document.pdf", "Text Processing") |
| assert test_job.document_name == "test_document.pdf" |
| print("β
Successfully added new job to queue") |
| |
| |
| processing_queue.update_job(test_job, True, "Test AI Model", 5) |
| assert test_job.success == True |
| assert test_job.entities_found == 5 |
| print("β
Successfully updated job completion status") |
| |
| |
| df = processing_queue.get_queue_dataframe() |
| assert len(df) > 0, "DataFrame should have data" |
| print(f"β
Successfully generated DataFrame with {len(df)} rows") |
| |
| |
| stats = processing_queue.get_session_statistics() |
| assert "total_processed" in stats |
| assert "avg_processing_time" in stats |
| print("β
Successfully generated session statistics") |
| |
| print("\nπ All processing queue tests passed!") |
| return True |
| |
| except Exception as e: |
| print(f"β Processing queue test failed: {e}") |
| import traceback |
| traceback.print_exc() |
| return False |
|
|
| def test_gradio_interface(): |
| """Test that the Gradio interface can be created""" |
| print("\nπ¨ Testing Gradio Interface Creation...") |
| |
| try: |
| import gradio as gr |
| from frontend_ui import create_processing_queue_tab |
| |
| |
| with gr.Blocks() as test_interface: |
| queue_components = create_processing_queue_tab() |
| |
| assert "queue_df" in queue_components |
| assert "stats_json" in queue_components |
| print("β
Successfully created processing queue Gradio interface") |
| |
| return True |
| |
| except Exception as e: |
| print(f"β Gradio interface test failed: {e}") |
| import traceback |
| traceback.print_exc() |
| return False |
|
|
| def test_integration_functions(): |
| """Test the workflow integration functions""" |
| print("\nπ Testing Workflow Integration...") |
| |
| try: |
| from frontend_ui import integrate_with_workflow, complete_workflow_job |
| |
| |
| job = integrate_with_workflow("integration_test.txt", "Integration Test") |
| assert job.document_name == "integration_test.txt" |
| print("β
Successfully integrated with workflow") |
| |
| |
| complete_workflow_job(job, True, "Integration AI", 10) |
| assert job.success == True |
| print("β
Successfully completed workflow job") |
| |
| return True |
| |
| except Exception as e: |
| print(f"β Integration test failed: {e}") |
| import traceback |
| traceback.print_exc() |
| return False |
|
|
| def main(): |
| """Run all tests""" |
| print("π₯ FhirFlame Processing Queue Test Suite") |
| print("=" * 50) |
| |
| tests = [ |
| ("Processing Queue Core", test_processing_queue), |
| ("Gradio Interface", test_gradio_interface), |
| ("Workflow Integration", test_integration_functions) |
| ] |
| |
| passed = 0 |
| total = len(tests) |
| |
| for test_name, test_func in tests: |
| print(f"\nπ§ͺ Running {test_name}...") |
| try: |
| if test_func(): |
| passed += 1 |
| print(f"β
{test_name} passed") |
| else: |
| print(f"β {test_name} failed") |
| except Exception as e: |
| print(f"β {test_name} failed with exception: {e}") |
| |
| print(f"\nπ Test Results: {passed}/{total} tests passed") |
| |
| if passed == total: |
| print("π All tests passed! Processing Queue is ready!") |
| print("\nπ To see the processing queue in action:") |
| print(" 1. Run: python app.py") |
| print(" 2. Navigate to the 'π Processing Queue' tab") |
| print(" 3. Click 'Add Demo Job' to see real-time updates") |
| return 0 |
| else: |
| print("β Some tests failed. Check the output above for details.") |
| return 1 |
|
|
| if __name__ == "__main__": |
| exit(main()) |