PrashanthB461 commited on
Commit
3da661b
·
verified ·
1 Parent(s): ebccb4c

Update tests/test_gradio.py

Browse files
Files changed (1) hide show
  1. tests/test_gradio.py +30 -23
tests/test_gradio.py CHANGED
@@ -1,33 +1,40 @@
1
  import pytest
2
- import sys
3
- import os
4
  import numpy as np
5
  from PIL import Image
6
 
7
- # Add the parent directory to the path to import app
8
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
-
10
- def test_gradio_interface():
11
- """Test Gradio interface components"""
12
- # Test model initialization simulation
13
- def mock_initialize_model():
14
- return "Model initialized successfully", None, None, None
15
 
16
- result = mock_initialize_model()
17
- assert "successfully" in result[0].lower(), "Model initialization failed"
18
 
19
- def test_process_image():
20
- """Test image processing functionality"""
 
 
 
 
21
  # Create a dummy image
22
  image = Image.fromarray(np.zeros((640, 640, 3), dtype=np.uint8))
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- # Mock the process_image function behavior
25
- def mock_process_image(img):
26
- if img is not None:
27
- return img, "Image processed successfully. No violations detected. Processing time: 0.1 seconds.", None, []
28
- else:
29
- return None, "Error: No image provided", None, []
30
 
31
- output_image, output_text, pdf_output, violations = mock_process_image(image)
32
- assert output_text is not None, "Process image returned None"
33
- assert "processed successfully" in output_text.lower(), "Image processing failed"
 
1
  import pytest
2
+ import gradio as gr
3
+ from app import process_image, initialize_model
4
  import numpy as np
5
  from PIL import Image
6
 
7
+ def test_initialize_model():
8
+ """Test model initialization through Gradio interface"""
9
+ result = initialize_model()
10
+ assert isinstance(result, tuple), "Initialize model should return a tuple"
11
+ assert len(result) == 4, "Initialize model should return 4 values"
 
 
 
12
 
13
+ status_message = result[0]
14
+ assert isinstance(status_message, str), "Status message should be a string"
15
 
16
+ def test_process_image_no_model():
17
+ """Test image processing without initialized model"""
18
+ # Reset global model to None
19
+ import app
20
+ app.yolo_model = None
21
+
22
  # Create a dummy image
23
  image = Image.fromarray(np.zeros((640, 640, 3), dtype=np.uint8))
24
+ result = process_image(image)
25
+
26
+ assert isinstance(result, tuple), "Process image should return a tuple"
27
+ assert len(result) == 4, "Process image should return 4 values"
28
+
29
+ output_image, output_text, pdf_file, violations = result
30
+ assert "not initialized" in output_text.lower(), "Should indicate model not initialized"
31
+
32
+ def test_process_image_no_input():
33
+ """Test image processing with no image input"""
34
+ result = process_image(None)
35
 
36
+ assert isinstance(result, tuple), "Process image should return a tuple"
37
+ assert len(result) == 4, "Process image should return 4 values"
 
 
 
 
38
 
39
+ output_image, output_text, pdf_file, violations = result
40
+ assert "no image" in output_text.lower(), "Should indicate no image provided"