#!/usr/bin/env python3 """ 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: # Import the processing queue components from frontend_ui import ProcessingQueue, ProcessingJob, processing_queue print("โœ… Successfully imported processing queue components") # Test queue initialization assert len(processing_queue.jobs) > 0, "Queue should have demo data" print(f"โœ… Queue initialized with {len(processing_queue.jobs)} demo jobs") # Test adding a new job 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") # Test updating job completion 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") # Test getting queue as DataFrame df = processing_queue.get_queue_dataframe() assert len(df) > 0, "DataFrame should have data" print(f"โœ… Successfully generated DataFrame with {len(df)} rows") # Test getting session statistics 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 # Test creating the 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 # Test integration job = integrate_with_workflow("integration_test.txt", "Integration Test") assert job.document_name == "integration_test.txt" print("โœ… Successfully integrated with workflow") # Test completion 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())