Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
talmo committed May 1, 2024
1 parent cb0c07e commit f40d556
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
23 changes: 22 additions & 1 deletion tests/io/test_video_backends.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
26 changes: 23 additions & 3 deletions tests/model/test_video.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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

0 comments on commit f40d556

Please sign in to comment.