coverage for video tests

This commit is contained in:
sneakers-the-rat 2024-05-20 21:20:56 -07:00
parent a4d82f0879
commit a948a41663
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
2 changed files with 10 additions and 8 deletions

View file

@ -12,7 +12,7 @@ from numpydantic.interface.interface import Interface
try: try:
import cv2 import cv2
from cv2 import VideoCapture from cv2 import VideoCapture
except ImportError: except ImportError: # pragma: no cover
cv2 = None cv2 = None
VideoCapture = None VideoCapture = None
@ -27,7 +27,7 @@ class VideoProxy:
def __init__( def __init__(
self, path: Optional[Path] = None, video: Optional[VideoCapture] = None self, path: Optional[Path] = None, video: Optional[VideoCapture] = None
): ):
if path is None and video is None: if path is None and video is None: # pragma: no cover
raise ValueError( raise ValueError(
"Need to either supply a path or an opened VideoCapture object" "Need to either supply a path or an opened VideoCapture object"
) )
@ -46,7 +46,7 @@ class VideoProxy:
def video(self) -> VideoCapture: def video(self) -> VideoCapture:
"""Opened video capture object""" """Opened video capture object"""
if self._video is None: if self._video is None:
if self.path is None: if self.path is None: # pragma: no cover
raise RuntimeError( raise RuntimeError(
"Instantiated with a VideoCapture object that has been closed, " "Instantiated with a VideoCapture object that has been closed, "
"and it cant be reopened since source path cant be gotten " "and it cant be reopened since source path cant be gotten "
@ -104,8 +104,10 @@ class VideoProxy:
t""" t"""
if self._n_frames is None: if self._n_frames is None:
n_frames = self.video.get(cv2.CAP_PROP_FRAME_COUNT) n_frames = self.video.get(cv2.CAP_PROP_FRAME_COUNT)
if n_frames == 0: if n_frames == 0: # pragma: no cover
# have to count manually for some containers with bad metadata # have to count manually for some containers with bad metadata
# not testing for now, will wait until we encounter such a
# video in the wild where this doesn't work.
current_frame = self.video.get(cv2.CAP_PROP_POS_FRAMES) current_frame = self.video.get(cv2.CAP_PROP_POS_FRAMES)
self.video.set(cv2.CAP_PROP_POS_FRAMES, 0) self.video.set(cv2.CAP_PROP_POS_FRAMES, 0)
n_frames = 0 n_frames = 0
@ -204,7 +206,7 @@ class VideoInterface(Interface):
if isinstance(array, str): if isinstance(array, str):
try: try:
array = Path(array) array = Path(array)
except TypeError: except TypeError: # pragma: no cover
# fine, just not a video # fine, just not a video
return False return False

View file

@ -47,8 +47,8 @@ def avi_video(tmp_path):
video_path.unlink(missing_ok=True) video_path.unlink(missing_ok=True)
@pytest.mark.parametrize('input_type', [str, Path])
def test_video_validation(avi_video): def test_video_validation(avi_video, input_type):
"""Color videos should validate for normal uint8 shape specs""" """Color videos should validate for normal uint8 shape specs"""
shape = (100, 50) shape = (100, 50)
@ -59,7 +59,7 @@ def test_video_validation(avi_video):
array: NDArray[Shape[shape_str], dt.UInt8] array: NDArray[Shape[shape_str], dt.UInt8]
# should correctly validate :) # should correctly validate :)
instance = MyModel(array=vid) instance = MyModel(array=input_type(vid))
assert isinstance(instance.array, VideoProxy) assert isinstance(instance.array, VideoProxy)