import pytest class TestGradioInterface: """Test Gradio interface functionality""" def test_gradio_generate_soap_empty_inputs(self): """Test Gradio function with empty inputs""" def mock_gradio_generate_soap(medical_notes, uploaded_image): text_to_process = medical_notes.strip() if medical_notes else "" if uploaded_image is not None: # Mock OCR extraction extracted_text = "Extracted text from image" if not text_to_process: text_to_process = extracted_text if not text_to_process: return "❌ Please enter medical notes manually or upload a PNG/JPG image with medical text" return "Generated SOAP note" result = mock_gradio_generate_soap("", None) assert "❌ Please enter medical notes manually" in result def test_gradio_generate_soap_with_text(self, sample_medical_text): """Test Gradio function with text input""" def mock_gradio_generate_soap(medical_notes, uploaded_image): text_to_process = medical_notes.strip() if medical_notes else "" if not text_to_process: return "❌ Please enter medical notes manually or upload a PNG/JPG image with medical text" return "Generated SOAP note from: " + text_to_process[:50] + "..." result = mock_gradio_generate_soap(sample_medical_text, None) assert "Generated SOAP note from:" in result assert "Patient: John Smith" in result def test_gradio_generate_soap_with_image(self, sample_image): """Test Gradio function with image input""" def mock_gradio_generate_soap(medical_notes, uploaded_image): text_to_process = medical_notes.strip() if medical_notes else "" if uploaded_image is not None: # Mock OCR extraction extracted_text = "Patient reports chest pain for 2 hours" if not text_to_process: text_to_process = extracted_text else: text_to_process = f"{text_to_process}\n\n--- Extracted from image ---\n{extracted_text}" if not text_to_process: return "❌ Please enter medical notes manually or upload a PNG/JPG image with medical text" return f"Generated SOAP note with {len(text_to_process)} characters" result = mock_gradio_generate_soap("", sample_image) assert "Generated SOAP note with" in result assert "characters" in result def test_gradio_generate_soap_text_and_image(self, sample_medical_text, sample_image): """Test Gradio function with both text and image""" def mock_gradio_generate_soap(medical_notes, uploaded_image): text_to_process = medical_notes.strip() if medical_notes else "" if uploaded_image is not None: extracted_text = "Additional findings from image" if text_to_process: text_to_process = f"{text_to_process}\n\n--- Extracted from image ---\n{extracted_text}" else: text_to_process = extracted_text return f"Combined input processed: {len(text_to_process)} chars" result = mock_gradio_generate_soap(sample_medical_text, sample_image) assert "Combined input processed:" in result assert "--- Extracted from image ---" in result or "chars" in result def test_gradio_error_handling(self): """Test error handling in Gradio interface""" def mock_gradio_generate_soap(medical_notes, uploaded_image): try: # Simulate an error condition if medical_notes == "ERROR_TEST": raise Exception("Simulated processing error") text_to_process = medical_notes.strip() if medical_notes else "" if not text_to_process and uploaded_image is None: return "❌ Please enter medical notes manually or upload a PNG/JPG image with medical text" return "Success" except Exception as e: return f"❌ Error generating SOAP note: {str(e)}" # Test error case result = mock_gradio_generate_soap("ERROR_TEST", None) assert "❌ Error generating SOAP note:" in result # Test empty input case result = mock_gradio_generate_soap("", None) assert "❌ Please enter medical notes manually" in result # Test success case result = mock_gradio_generate_soap("Valid input", None) assert result == "Success"