Update tests/test_gradio.py
Browse files- tests/test_gradio.py +30 -23
tests/test_gradio.py
CHANGED
|
@@ -1,33 +1,40 @@
|
|
| 1 |
import pytest
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
"
|
| 12 |
-
# Test model initialization simulation
|
| 13 |
-
def mock_initialize_model():
|
| 14 |
-
return "Model initialized successfully", None, None, None
|
| 15 |
|
| 16 |
-
|
| 17 |
-
assert
|
| 18 |
|
| 19 |
-
def
|
| 20 |
-
"""Test image processing
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Create a dummy image
|
| 22 |
image = Image.fromarray(np.zeros((640, 640, 3), dtype=np.uint8))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 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,
|
| 32 |
-
assert
|
| 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"
|
|
|