Spaces:
Runtime error
Runtime error
| import pytest | |
| from app import capture_rtsp_frames | |
| from unittest.mock import patch | |
| import cv2 | |
| 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() |