Spaces:
Sleeping
Sleeping
File size: 4,883 Bytes
b98bc58 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
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" |