diff --git a/tests/io/test_video_backends.py b/tests/io/test_video_backends.py index deb22ce3..06f22050 100644 --- a/tests/io/test_video_backends.py +++ b/tests/io/test_video_backends.py @@ -1,10 +1,11 @@ """Tests for methods in the sleap_io.io.video file.""" -from sleap_io.io.video import VideoBackend, MediaVideo, HDF5Video +from sleap_io.io.video import VideoBackend, MediaVideo, HDF5Video, ImageVideo import numpy as np from numpy.testing import assert_equal import h5py import pytest +from pathlib import Path def test_video_backend_from_filename(centered_pair_low_quality_path, slp_minimal_pkg): @@ -140,3 +141,23 @@ def test_hdf5video_embedded(slp_minimal_pkg): == "tests/data/json_format_v1/centered_pair_low_quality.mp4" ) assert backend.has_embedded_images + + +def test_imagevideo(centered_pair_frame_paths): + backend = VideoBackend.from_filename(centered_pair_frame_paths) + assert type(backend) == ImageVideo + assert backend.shape == (3, 384, 384, 1) + assert backend[0].shape == (384, 384, 1) + assert backend[:3].shape == (3, 384, 384, 1) + + img_folder = Path(centered_pair_frame_paths[0]).parent + imgs = ImageVideo.find_images(img_folder) + assert imgs == centered_pair_frame_paths + + backend = VideoBackend.from_filename(img_folder) + assert type(backend) == ImageVideo + assert backend.shape == (3, 384, 384, 1) + + backend = VideoBackend.from_filename(centered_pair_frame_paths[0]) + assert type(backend) == ImageVideo + assert backend.shape == (1, 384, 384, 1) diff --git a/tests/model/test_video.py b/tests/model/test_video.py index d7839f90..0ccd13c2 100644 --- a/tests/model/test_video.py +++ b/tests/model/test_video.py @@ -1,7 +1,7 @@ """Tests for methods in the sleap_io.model.video file.""" from sleap_io import Video -from sleap_io.io.video import MediaVideo +from sleap_io.io.video import MediaVideo, ImageVideo import numpy as np import pytest from pathlib import Path @@ -36,12 +36,24 @@ def test_video_repr(centered_pair_low_quality_video): ) -def test_video_exists(centered_pair_low_quality_video): +def test_video_exists(centered_pair_low_quality_video, centered_pair_frame_paths): video = Video("test.mp4") assert video.exists() is False assert centered_pair_low_quality_video.exists() is True + video = Video(centered_pair_frame_paths) + assert video.exists() is True + assert video.exists(check_all=True) is True + + video = Video([centered_pair_frame_paths[0], "fake.jpg"]) + assert video.exists() is True + assert video.exists(check_all=True) is False + + video = Video(["fake.jpg", centered_pair_frame_paths[0]]) + assert video.exists() is False + assert video.exists(check_all=True) is False + def test_video_open_close(centered_pair_low_quality_path): video = Video(centered_pair_low_quality_path) @@ -79,7 +91,9 @@ def test_video_open_close(centered_pair_low_quality_path): assert video.shape == (1100, 384, 384, 1) -def test_video_replace_filename(centered_pair_low_quality_path): +def test_video_replace_filename( + centered_pair_low_quality_path, centered_pair_frame_paths +): video = Video.from_filename("test.mp4") assert video.exists() is False @@ -101,3 +115,9 @@ def test_video_replace_filename(centered_pair_low_quality_path): assert video.exists() is True assert video.is_open is False assert video.backend is None + + video = Video.from_filename(["fake.jpg", "fake2.jpg", "fake3.jpg"]) + assert type(video.backend) == ImageVideo + video.replace_filename(centered_pair_frame_paths) + assert type(video.backend) == ImageVideo + assert video.exists(check_all=True) is True