diff --git a/tests/extras/datasets/video/test_sliced_video.py b/tests/extras/datasets/video/test_sliced_video.py index a84ae009c1..e2e4975d1a 100644 --- a/tests/extras/datasets/video/test_sliced_video.py +++ b/tests/extras/datasets/video/test_sliced_video.py @@ -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] diff --git a/tests/extras/datasets/video/test_video_objects.py b/tests/extras/datasets/video/test_video_objects.py index 0c63cb924b..66a284fa60 100644 --- a/tests/extras/datasets/video/test_video_objects.py +++ b/tests/extras/datasets/video/test_video_objects.py @@ -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: @@ -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]