-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from ll7/79-Create-videos-based-on-state-recor…
…dings Enhance load_states function and add video recording capability
- Loading branch information
Showing
3 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |