Skip to content

Commit 9271ca8

Browse files
huguesdevimeuxHugues Devimeuxbehackl
authored
fix #460 by enabling skipping wait statements. (#468)
* fix #460 by enabling skipping wait statements. * added tests * black, as always * Update tests/test_scene_rendering/test_caching_relalted.py Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: Hugues Devimeux <[email protected]> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent cc87ca4 commit 9271ca8

File tree

5 files changed

+91
-1
lines changed

5 files changed

+91
-1
lines changed

manim/scene/scene.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,6 @@ def update_skipping_status(self):
784784
the number of animations that need to be played, and
785785
raises an EndSceneEarlyException if they don't correspond.
786786
"""
787-
788787
if file_writer_config["from_animation_number"]:
789788
if self.num_plays < file_writer_config["from_animation_number"]:
790789
file_writer_config["skip_animations"] = True
@@ -848,6 +847,10 @@ def handle_caching_wait(func):
848847
def wrapper(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
849848
self.revert_to_original_skipping_status()
850849
self.update_skipping_status()
850+
if file_writer_config["skip_animations"]:
851+
logger.debug(f"Skipping wait {self.num_plays}")
852+
func(self, duration, stop_condition)
853+
return
851854
if not file_writer_config["disable_caching"]:
852855
hash_wait = get_hash_from_wait_call(
853856
self, self.camera, duration, stop_condition, self.get_mobjects()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "SceneWithMultiplePlayCallsWithNFlag",
3+
"config": {
4+
"codec_name": "h264",
5+
"width": 854,
6+
"height": 480,
7+
"avg_frame_rate": "15/1",
8+
"duration": "7.000000",
9+
"nb_frames": "105"
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "SceneWithMultipleWaitCallsWithNFlag",
3+
"config": {
4+
"codec_name": "h264",
5+
"width": 854,
6+
"height": 480,
7+
"avg_frame_rate": "15/1",
8+
"duration": "5.000000",
9+
"nb_frames": "75"
10+
}
11+
}

tests/test_scene_rendering/simple_scenes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ def construct(self):
1515
for i in range(10):
1616
number.become(Integer(i))
1717
self.play(Animation(number))
18+
19+
20+
class SceneWithMultipleWaitCalls(Scene):
21+
def construct(self):
22+
self.play(ShowCreation(Square()))
23+
self.wait(1)
24+
self.play(ShowCreation(Square().shift(DOWN)))
25+
self.wait(1)
26+
self.play(ShowCreation(Square().shift(2 * DOWN)))
27+
self.wait(1)
28+
self.play(ShowCreation(Square().shift(3 * DOWN)))
29+
self.wait(1)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
import pytest
3+
import subprocess
4+
from manim import file_writer_config
5+
6+
from ..utils.commands import capture
7+
from ..utils.video_tester import video_comparison
8+
9+
10+
@video_comparison(
11+
"SceneWithMultipleWaitCallsWithNFlag.json",
12+
"videos/simple_scenes/480p15/SceneWithMultipleWaitCalls.mp4",
13+
)
14+
def test_wait_skip(tmp_path, manim_cfg_file, simple_scenes_path):
15+
# Test for PR #468. Intended to test if wait calls are correctly skipped.
16+
scene_name = "SceneWithMultipleWaitCalls"
17+
command = [
18+
"python",
19+
"-m",
20+
"manim",
21+
simple_scenes_path,
22+
scene_name,
23+
"-l",
24+
"--media_dir",
25+
str(tmp_path),
26+
"-n",
27+
"3",
28+
]
29+
out, err, exit_code = capture(command)
30+
assert exit_code == 0, err
31+
32+
33+
@video_comparison(
34+
"SceneWithMultiplePlayCallsWithNFlag.json",
35+
"videos/simple_scenes/480p15/SceneWithMultipleCalls.mp4",
36+
)
37+
def test_play_skip(tmp_path, manim_cfg_file, simple_scenes_path):
38+
# Intended to test if play calls are correctly skipped.
39+
scene_name = "SceneWithMultipleCalls"
40+
command = [
41+
"python",
42+
"-m",
43+
"manim",
44+
simple_scenes_path,
45+
scene_name,
46+
"-l",
47+
"--media_dir",
48+
str(tmp_path),
49+
"-n",
50+
"3",
51+
]
52+
out, err, exit_code = capture(command)
53+
assert exit_code == 0, err

0 commit comments

Comments
 (0)