A community-maintained Python framework for creating mathematical animations.
fix #460 by enabling skipping wait statements. (#468)
Hugues Devimeux9271ca88936b
diff --git a/manim/scene/scene.py b/manim/scene/scene.pyindex e3f992551..249f6b04c 100644--- a/manim/scene/scene.py+++ b/manim/scene/scene.py@@ -784,7 +784,6 @@ class Scene(Container):the number of animations that need to be played, andraises an EndSceneEarlyException if they don't correspond."""-if file_writer_config["from_animation_number"]:if self.num_plays < file_writer_config["from_animation_number"]:file_writer_config["skip_animations"] = True@@ -848,6 +847,10 @@ class Scene(Container):def wrapper(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):self.revert_to_original_skipping_status()self.update_skipping_status()+ if file_writer_config["skip_animations"]:+ logger.debug(f"Skipping wait {self.num_plays}")+ func(self, duration, stop_condition)+ returnif not file_writer_config["disable_caching"]:hash_wait = get_hash_from_wait_call(self, self.camera, duration, stop_condition, self.get_mobjects()diff --git a/tests/control_data/videos_data/SceneWithMultiplePlayCallsWithNFlag.json b/tests/control_data/videos_data/SceneWithMultiplePlayCallsWithNFlag.jsonnew file mode 100644index 000000000..ad2ea0fac--- /dev/null+++ b/tests/control_data/videos_data/SceneWithMultiplePlayCallsWithNFlag.json@@ -0,0 +1,11 @@+{+ "name": "SceneWithMultiplePlayCallsWithNFlag",+ "config": {+ "codec_name": "h264",+ "width": 854,+ "height": 480,+ "avg_frame_rate": "15/1",+ "duration": "7.000000",+ "nb_frames": "105"+ }+}\ No newline at end of filediff --git a/tests/control_data/videos_data/SceneWithMultipleWaitCallsWithNFlag.json b/tests/control_data/videos_data/SceneWithMultipleWaitCallsWithNFlag.jsonnew file mode 100644index 000000000..05ae9e038--- /dev/null+++ b/tests/control_data/videos_data/SceneWithMultipleWaitCallsWithNFlag.json@@ -0,0 +1,11 @@+{+ "name": "SceneWithMultipleWaitCallsWithNFlag",+ "config": {+ "codec_name": "h264",+ "width": 854,+ "height": 480,+ "avg_frame_rate": "15/1",+ "duration": "5.000000",+ "nb_frames": "75"+ }+}\ No newline at end of filediff --git a/tests/test_scene_rendering/simple_scenes.py b/tests/test_scene_rendering/simple_scenes.pyindex 64e6b4f42..b05c27575 100644--- a/tests/test_scene_rendering/simple_scenes.py+++ b/tests/test_scene_rendering/simple_scenes.py@@ -15,3 +15,15 @@ class SceneWithMultipleCalls(Scene):for i in range(10):number.become(Integer(i))self.play(Animation(number))+++class SceneWithMultipleWaitCalls(Scene):+ def construct(self):+ self.play(ShowCreation(Square()))+ self.wait(1)+ self.play(ShowCreation(Square().shift(DOWN)))+ self.wait(1)+ self.play(ShowCreation(Square().shift(2 * DOWN)))+ self.wait(1)+ self.play(ShowCreation(Square().shift(3 * DOWN)))+ self.wait(1)diff --git a/tests/test_scene_rendering/test_caching_relalted.py b/tests/test_scene_rendering/test_caching_relalted.pynew file mode 100644index 000000000..48080f4c1--- /dev/null+++ b/tests/test_scene_rendering/test_caching_relalted.py@@ -0,0 +1,53 @@+import os+import pytest+import subprocess+from manim import file_writer_config++from ..utils.commands import capture+from ..utils.video_tester import video_comparison+++@video_comparison(+ "SceneWithMultipleWaitCallsWithNFlag.json",+ "videos/simple_scenes/480p15/SceneWithMultipleWaitCalls.mp4",+)+def test_wait_skip(tmp_path, manim_cfg_file, simple_scenes_path):+ # Test for PR #468. Intended to test if wait calls are correctly skipped.+ scene_name = "SceneWithMultipleWaitCalls"+ command = [+ "python",+ "-m",+ "manim",+ simple_scenes_path,+ scene_name,+ "-l",+ "--media_dir",+ str(tmp_path),+ "-n",+ "3",+ ]+ out, err, exit_code = capture(command)+ assert exit_code == 0, err+++@video_comparison(+ "SceneWithMultiplePlayCallsWithNFlag.json",+ "videos/simple_scenes/480p15/SceneWithMultipleCalls.mp4",+)+def test_play_skip(tmp_path, manim_cfg_file, simple_scenes_path):+ # Intended to test if play calls are correctly skipped.+ scene_name = "SceneWithMultipleCalls"+ command = [+ "python",+ "-m",+ "manim",+ simple_scenes_path,+ scene_name,+ "-l",+ "--media_dir",+ str(tmp_path),+ "-n",+ "3",+ ]+ out, err, exit_code = capture(command)+ assert exit_code == 0, err