Skip to content

Commit

Permalink
feat: add pytest for load_states_and_record_video function with video…
Browse files Browse the repository at this point in the history
… recording validation
  • Loading branch information
ll7 committed Dec 11, 2024
1 parent 1e4b3e9 commit 5d3b832
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/test_load_states_and_record_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""pytest for load_states_and_record_video.py"""

import pytest
import datetime
from robot_sf.render.playback_recording import load_states_and_record_video
from robot_sf.render.sim_view import MOVIEPY_AVAILABLE
from pathlib import Path


@pytest.mark.skipif(
not MOVIEPY_AVAILABLE, reason="MoviePy/ffmpeg not available for video recording"
)
def test_load_states_and_record_video(delete_video: bool = True):
"""Test loading simulation states and recording them as video.
Args:
delete_video: Whether to delete the video file after test. Default True.
"""
# Create recordings directory if it doesn't exist
recordings_dir = Path("recordings")
recordings_dir.mkdir(exist_ok=True)

# create a unique video name
video_name = "playback_test_" + datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".mp4"

output_path = recordings_dir / video_name

try:
load_states_and_record_video(
"test_pygame/recordings/2024-06-04_08-39-59.pkl", str(output_path)
)

assert output_path.exists(), "Video file was not created"
assert output_path.stat().st_size > 0, "Video file is empty"
finally:
# Clean up
if output_path.exists() and delete_video:
output_path.unlink()



if __name__ == "__main__":
test_load_states_and_record_video(delete_video=False)

0 comments on commit 5d3b832

Please sign in to comment.