Skip to content

Commit 0f8e116

Browse files
committed
add tests
1 parent 08e6133 commit 0f8e116

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

agents-core/vision_agents/core/utils/video_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def ensure_even_dimensions(frame: av.VideoFrame) -> av.VideoFrame:
2020

2121
cropped = frame.reformat(width=new_width, height=new_height)
2222
cropped.pts = frame.pts
23-
cropped.time_base = frame.time_base
23+
if frame.time_base is not None:
24+
cropped.time_base = frame.time_base
2425

2526
return cropped
2627

tests/test_utils.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
22
import tempfile
33
import numpy as np
4+
import av
45
from vision_agents.core.utils.utils import parse_instructions, Instructions
6+
from vision_agents.core.utils.video_utils import ensure_even_dimensions
57
from vision_agents.core.edge.types import PcmData
68

79

@@ -441,5 +443,39 @@ def test_pcm_data_resample_av_array_shape_fix(self):
441443
assert resampled.samples.ndim == 1
442444

443445

444-
# Shared fixtures for integration tests
445-
446+
class TestEnsureEvenDimensions:
447+
"""Test suite for ensure_even_dimensions function."""
448+
449+
def test_even_dimensions_unchanged(self):
450+
"""Test that frames with even dimensions pass through unchanged."""
451+
# Create a frame with even dimensions (1920x1080)
452+
frame = av.VideoFrame(width=1920, height=1080, format="yuv420p")
453+
454+
result = ensure_even_dimensions(frame)
455+
456+
assert result.width == 1920
457+
assert result.height == 1080
458+
459+
def test_both_dimensions_odd_cropped(self):
460+
"""Test that frames with both odd dimensions are cropped."""
461+
# Create a frame with both odd dimensions (1921x1081)
462+
frame = av.VideoFrame(width=1921, height=1081, format="yuv420p")
463+
464+
result = ensure_even_dimensions(frame)
465+
466+
assert result.width == 1920 # Cropped from 1921
467+
assert result.height == 1080 # Cropped from 1081
468+
469+
def test_timing_information_preserved(self):
470+
"""Test that pts and time_base are preserved after cropping."""
471+
from fractions import Fraction
472+
473+
# Create a frame with timing information
474+
frame = av.VideoFrame(width=1921, height=1081, format="yuv420p")
475+
frame.pts = 12345
476+
frame.time_base = Fraction(1, 30)
477+
478+
result = ensure_even_dimensions(frame)
479+
480+
assert result.pts == 12345
481+
assert result.time_base == Fraction(1, 30)

0 commit comments

Comments
 (0)