Skip to content

Commit

Permalink
Fix tests and python matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-romero committed Nov 17, 2024
1 parent b1252c3 commit e468f32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 36 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ jobs:
fail-fast: false
matrix:
python-version: [
# "3.7",
"3.8",
#"3.9",
"3.10",
#"3.11",
"3.9",
"3.10",
"3.11",
]
steps:
- name: get code
Expand Down
43 changes: 12 additions & 31 deletions test/test_framegrab_with_hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ def setUp(self):
}

@patch("cv2.VideoCapture")
def test_init_with_valid_config(self, mock_cv2):
def test_grab_frame_success(self, mock_cv2):
"""Test that the grabber initializes correctly with a valid config"""
# Setup mock
mock_capture = MagicMock()
mock_capture.isOpened.return_value = True
mock_capture.read.return_value = (True, self.mock_frame)
mock_cv2.return_value = mock_capture

grabber = HttpLiveStreamingFrameGrabber(self.base_config)

self.assertEqual(grabber.hls_url, "http://example.com/stream.m3u8")

frame = grabber.grab()
mock_cv2.assert_called_once_with("http://example.com/stream.m3u8")
mock_capture.read.assert_called_once()
self.assertEqual(frame.shape, (480, 640, 3))
mock_capture.release.assert_called_once()

def test_init_without_hls_url(self):
"""Test that initialization fails without an HLS URL"""
Expand All @@ -37,31 +42,18 @@ def test_init_without_hls_url(self):
HttpLiveStreamingFrameGrabber(config)

@patch("cv2.VideoCapture")
def test_init_with_failed_connection(self, mock_cv2):
def test_grab_with_failed_connection(self, mock_cv2):
"""Test that initialization fails when the stream cannot be opened"""
# Setup mock
mock_capture = MagicMock()
mock_capture.isOpened.return_value = False
mock_cv2.return_value = mock_capture

with self.assertRaises(ValueError):
HttpLiveStreamingFrameGrabber(self.base_config)

@patch("cv2.VideoCapture")
def test_grab_frame_success(self, mock_cv2):
"""Test successful frame grab"""
# Setup mock
mock_capture = MagicMock()
mock_capture.isOpened.return_value = True
mock_capture.read.return_value = (True, self.mock_frame)
mock_capture.retrieve.return_value = (True, self.mock_frame)
mock_cv2.return_value = mock_capture

grabber = HttpLiveStreamingFrameGrabber(self.base_config)
frame = grabber.grab()
with self.assertRaises(ValueError) as cm:
grabber = HttpLiveStreamingFrameGrabber(self.base_config)
grabber.grab()

self.assertIsNotNone(frame)
self.assertEqual(frame.shape, (480, 640, 3))
self.assertIn("Could not open HLS stream", str(cm.exception))

@patch("cv2.VideoCapture")
def test_grab_frame_failure(self, mock_cv2):
Expand All @@ -78,17 +70,6 @@ def test_grab_frame_failure(self, mock_cv2):
with self.assertRaises(Exception):
grabber.grab()

@patch("cv2.VideoCapture")
def test_release(self, mock_cv2):
"""Test that release properly closes the connection"""
# Setup mock
mock_capture = MagicMock()
mock_capture.isOpened.return_value = True
mock_cv2.return_value = mock_capture

grabber = HttpLiveStreamingFrameGrabber(self.base_config)
grabber.release()

mock_capture.release.assert_called_once()

@patch("cv2.VideoCapture")
Expand Down

0 comments on commit e468f32

Please sign in to comment.