Skip to content

Commit

Permalink
Add unit tests to video dataset to get 100% coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Falk <Daniel.Falk.1@FixedIT.ai>
  • Loading branch information
daniel-falk committed Jul 3, 2022
1 parent 243d817 commit 8c6b699
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/extras/datasets/video/test_sliced_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def test_slice_sequence_video_last_as_end(self, color_video):
assert np.all(purple[:, :, 1] == 0)
assert np.all(purple[:, :, 2] == 255)

def test_slice_sequence_attribute(self, color_video):
"""Test that attributes from the base class are reachable from sliced views"""
slice_red_green = color_video[:2]
assert slice_red_green.fps == color_video.fps

def test_slice_sliced_video(self, color_video):
"""Test slicing and then indexing a SlicedVideo"""
slice_green_blue_yellow = color_video[1:4]
Expand Down
25 changes: 24 additions & 1 deletion tests/extras/datasets/video/test_video_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
assert_images_equal,
)

from kedro.extras.datasets.video.video_dataset import GeneratorVideo, SequenceVideo
from kedro.extras.datasets.video.video_dataset import (
FileVideo,
GeneratorVideo,
SequenceVideo,
)


class TestSequenceVideo:
Expand Down Expand Up @@ -145,3 +149,22 @@ def test_file_index_last_by_index(self, color_video_object, purple_frame):

def test_file_index_last(self, color_video_object, purple_frame):
assert_images_equal(color_video_object[-1], purple_frame)

def test_file_video_failed_capture(self, mocker):
"""Validate good behavior on failed decode
The best behavior in this case is not obvious, the len property of the
video object specifies more frames than is actually possible to decode. We
cannot know this in advance without spending loads of time to decode all frames
in order to count them."""
mock_cv2 = mocker.patch("kedro.extras.datasets.video.video_dataset.cv2")
mock_cap = mock_cv2.VideoCapture.return_value = mocker.Mock()
mock_cap.get.return_value = 2 # Set the length of the video
ds = FileVideo("/a/b/c")

mock_cap.read.return_value = True, np.zeros((1, 1))
assert ds[0]

mock_cap.read.return_value = False, None
with pytest.raises(IndexError):
ds[1]

0 comments on commit 8c6b699

Please sign in to comment.