PrashanthB461 commited on
Commit
15c8303
·
verified ·
1 Parent(s): 5ef6e4d

Create test_rtsp.py

Browse files
Files changed (1) hide show
  1. tests/test_rtsp.py +17 -0
tests/test_rtsp.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ from app import capture_rtsp_frames
3
+ from unittest.mock import patch
4
+ import cv2
5
+
6
+ @patch('cv2.VideoCapture')
7
+ def test_rtsp_connection(mock_video_capture):
8
+ # Mock VideoCapture to simulate a successful connection
9
+ mock_instance = mock_video_capture.return_value
10
+ mock_instance.isOpened.return_value = True
11
+ mock_instance.read.side_effect = [(True, None), (False, None)] # Simulate one frame then stop
12
+
13
+ rtsp_url = "rtsp://test:8554/stream"
14
+ frames = list(capture_rtsp_frames(rtsp_url)) # Consume generator
15
+ assert len(frames) == 1, "Expected one frame from mocked RTSP stream"
16
+ mock_video_capture.assert_called_with(rtsp_url)
17
+ mock_instance.release.assert_called_once()