feat: 修复 AI 风险语义并隔离 Mock 数据
This commit is contained in:
@@ -2,7 +2,7 @@ import base64
|
||||
|
||||
import pytest
|
||||
|
||||
from app.detector import MockDetector
|
||||
from app.detector import MockDetector, abnormal_probability, detection_status
|
||||
|
||||
# 1x1 透明 PNG
|
||||
TINY_PNG = base64.b64decode(
|
||||
@@ -23,3 +23,22 @@ def test_mock_detector_rejects_invalid_image():
|
||||
det = MockDetector()
|
||||
with pytest.raises(ValueError):
|
||||
det.detect(b"not an image")
|
||||
|
||||
|
||||
def test_abnormal_probability_ignores_healthy_and_unknown():
|
||||
detections = [
|
||||
{"class_name": "healthy", "confidence": 0.95},
|
||||
{"class_name": "unknown", "confidence": 0.8},
|
||||
{"class_name": "sick", "confidence": 0.72},
|
||||
]
|
||||
assert abnormal_probability(detections, ("healthy", "sick")) == 0.72
|
||||
|
||||
|
||||
def test_detection_status_returns_unknown_for_empty_or_unknown():
|
||||
assert detection_status([], ("healthy", "sick")) == "unknown"
|
||||
assert detection_status([{"class_name": "unknown", "confidence": 0.8}], ("healthy", "sick")) == "unknown"
|
||||
assert detection_status([{"class_name": "healthy", "confidence": 0.95}], ("healthy", "sick")) == "healthy"
|
||||
assert detection_status(
|
||||
[{"class_name": "white_muscardine", "confidence": 0.7}],
|
||||
("healthy", "white_muscardine", "nuclear_polyhedrosis"),
|
||||
) == "abnormal"
|
||||
|
||||
Reference in New Issue
Block a user