SafetyViolationAI1 / tests /test_rtsp.py
PrashanthB461's picture
Create test_rtsp.py
15c8303 verified
raw
history blame contribute delete
713 Bytes
import pytest
from app import capture_rtsp_frames
from unittest.mock import patch
import cv2
@patch('cv2.VideoCapture')
def test_rtsp_connection(mock_video_capture):
# Mock VideoCapture to simulate a successful connection
mock_instance = mock_video_capture.return_value
mock_instance.isOpened.return_value = True
mock_instance.read.side_effect = [(True, None), (False, None)] # Simulate one frame then stop
rtsp_url = "rtsp://test:8554/stream"
frames = list(capture_rtsp_frames(rtsp_url)) # Consume generator
assert len(frames) == 1, "Expected one frame from mocked RTSP stream"
mock_video_capture.assert_called_with(rtsp_url)
mock_instance.release.assert_called_once()