Bonosa2 commited on
Commit
b98bc58
Β·
verified Β·
1 Parent(s): 37d6469

Create tests/test_gradio_interface.py

Browse files
Files changed (1) hide show
  1. tests/test_gradio_interface.py +105 -0
tests/test_gradio_interface.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ class TestGradioInterface:
4
+ """Test Gradio interface functionality"""
5
+
6
+ def test_gradio_generate_soap_empty_inputs(self):
7
+ """Test Gradio function with empty inputs"""
8
+ def mock_gradio_generate_soap(medical_notes, uploaded_image):
9
+ text_to_process = medical_notes.strip() if medical_notes else ""
10
+
11
+ if uploaded_image is not None:
12
+ # Mock OCR extraction
13
+ extracted_text = "Extracted text from image"
14
+ if not text_to_process:
15
+ text_to_process = extracted_text
16
+
17
+ if not text_to_process:
18
+ return "❌ Please enter medical notes manually or upload a PNG/JPG image with medical text"
19
+
20
+ return "Generated SOAP note"
21
+
22
+ result = mock_gradio_generate_soap("", None)
23
+ assert "❌ Please enter medical notes manually" in result
24
+
25
+ def test_gradio_generate_soap_with_text(self, sample_medical_text):
26
+ """Test Gradio function with text input"""
27
+ def mock_gradio_generate_soap(medical_notes, uploaded_image):
28
+ text_to_process = medical_notes.strip() if medical_notes else ""
29
+
30
+ if not text_to_process:
31
+ return "❌ Please enter medical notes manually or upload a PNG/JPG image with medical text"
32
+
33
+ return "Generated SOAP note from: " + text_to_process[:50] + "..."
34
+
35
+ result = mock_gradio_generate_soap(sample_medical_text, None)
36
+ assert "Generated SOAP note from:" in result
37
+ assert "Patient: John Smith" in result
38
+
39
+ def test_gradio_generate_soap_with_image(self, sample_image):
40
+ """Test Gradio function with image input"""
41
+ def mock_gradio_generate_soap(medical_notes, uploaded_image):
42
+ text_to_process = medical_notes.strip() if medical_notes else ""
43
+
44
+ if uploaded_image is not None:
45
+ # Mock OCR extraction
46
+ extracted_text = "Patient reports chest pain for 2 hours"
47
+ if not text_to_process:
48
+ text_to_process = extracted_text
49
+ else:
50
+ text_to_process = f"{text_to_process}\n\n--- Extracted from image ---\n{extracted_text}"
51
+
52
+ if not text_to_process:
53
+ return "❌ Please enter medical notes manually or upload a PNG/JPG image with medical text"
54
+
55
+ return f"Generated SOAP note with {len(text_to_process)} characters"
56
+
57
+ result = mock_gradio_generate_soap("", sample_image)
58
+ assert "Generated SOAP note with" in result
59
+ assert "characters" in result
60
+
61
+ def test_gradio_generate_soap_text_and_image(self, sample_medical_text, sample_image):
62
+ """Test Gradio function with both text and image"""
63
+ def mock_gradio_generate_soap(medical_notes, uploaded_image):
64
+ text_to_process = medical_notes.strip() if medical_notes else ""
65
+
66
+ if uploaded_image is not None:
67
+ extracted_text = "Additional findings from image"
68
+ if text_to_process:
69
+ text_to_process = f"{text_to_process}\n\n--- Extracted from image ---\n{extracted_text}"
70
+ else:
71
+ text_to_process = extracted_text
72
+
73
+ return f"Combined input processed: {len(text_to_process)} chars"
74
+
75
+ result = mock_gradio_generate_soap(sample_medical_text, sample_image)
76
+ assert "Combined input processed:" in result
77
+ assert "--- Extracted from image ---" in result or "chars" in result
78
+
79
+ def test_gradio_error_handling(self):
80
+ """Test error handling in Gradio interface"""
81
+ def mock_gradio_generate_soap(medical_notes, uploaded_image):
82
+ try:
83
+ # Simulate an error condition
84
+ if medical_notes == "ERROR_TEST":
85
+ raise Exception("Simulated processing error")
86
+
87
+ text_to_process = medical_notes.strip() if medical_notes else ""
88
+ if not text_to_process and uploaded_image is None:
89
+ return "❌ Please enter medical notes manually or upload a PNG/JPG image with medical text"
90
+
91
+ return "Success"
92
+ except Exception as e:
93
+ return f"❌ Error generating SOAP note: {str(e)}"
94
+
95
+ # Test error case
96
+ result = mock_gradio_generate_soap("ERROR_TEST", None)
97
+ assert "❌ Error generating SOAP note:" in result
98
+
99
+ # Test empty input case
100
+ result = mock_gradio_generate_soap("", None)
101
+ assert "❌ Please enter medical notes manually" in result
102
+
103
+ # Test success case
104
+ result = mock_gradio_generate_soap("Valid input", None)
105
+ assert result == "Success"