e1250 commited on
Commit
50ffab2
·
1 Parent(s): 87aa1c0

feat: adding testing into git actiosn

Browse files
Files changed (1) hide show
  1. tests/test_pipeline.py +69 -0
tests/test_pipeline.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from backend.services.pipeline import ProcessingPipeline
2
+ import pytest
3
+ import numpy as np
4
+ from unittest.mock import MagicMock, AsyncMock, patch
5
+
6
+
7
+ @pytest.fixture
8
+ def mock_deps():
9
+ return {
10
+ "detector": MagicMock(),
11
+ "safety": MagicMock(),
12
+ "depth": MagicMock(),
13
+ "redis": AsyncMock(),
14
+ }
15
+
16
+
17
+ @pytest.mark.asyncio
18
+ async def test_pipeline_success(mock_deps):
19
+ mock_detection = MagicMock()
20
+ mock_detection.xyxy = [10, 10, 20, 20]
21
+ mock_detection.class_name = "person"
22
+
23
+ # Settings mock models values
24
+ mock_deps["detector"].detect.return_value.detections = [mock_detection]
25
+ mock_deps["safety"].detect.return_value = [] # No dangers
26
+
27
+ pipeline = ProcessingPipeline(
28
+ detector=mock_deps["detector"],
29
+ safety_detector=mock_deps["safety"],
30
+ depth_model=mock_deps["depth"],
31
+ redis=mock_deps["redis"],
32
+ )
33
+
34
+ with (
35
+ patch("cv2.imdecode") as mock_decode,
36
+ patch("backend.utils.profiling.mlflow") as mock_mlflow,
37
+ ):
38
+ mock_decode.return_value = np.zeros((100, 100, 3), dtype=np.uint8)
39
+
40
+ result = await pipeline.run(
41
+ camera_id="test", frame_bytes=b"test", frame_count=1
42
+ )
43
+
44
+ assert result["status"] == 200
45
+
46
+ mock_deps["depth"].calculate_depth.assert_called_once()
47
+ mock_deps["redis"].publish.assert_called_once()
48
+
49
+
50
+ @pytest.mark.asyncio
51
+ async def test_pipeline_no_detections(mock_deps):
52
+ mock_deps["detector"].detect.return_value.detections = []
53
+
54
+ pipeline = ProcessingPipeline(
55
+ detector=mock_deps["detector"],
56
+ safety_detector=mock_deps["safety"],
57
+ depth_model=mock_deps["depth"],
58
+ redis=mock_deps["redis"],
59
+ )
60
+
61
+ with (
62
+ patch("cv2.imdecode") as mock_decode,
63
+ patch("backend.utils.profiling.mlflow") as mock_mlflow,
64
+ ):
65
+ mock_decode.return_value = np.zeros((100, 100, 3), dtype=np.uint8)
66
+
67
+ await pipeline.run(camera_id="test", frame_bytes=b"test", frame_count=1)
68
+
69
+ mock_deps["depth"].calculate_depth.assert_not_called()