From a980b9097cecea846be2424e8b89e57d7b65fcb3 Mon Sep 17 00:00:00 2001 From: MrDiver Date: Tue, 5 Dec 2023 14:23:12 +0100 Subject: [PATCH 1/8] Fix animation group not erroring when instantiated with an empty list --- manim/animation/composition.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manim/animation/composition.py b/manim/animation/composition.py index cc6fa2ca7e..39770e8d4e 100644 --- a/manim/animation/composition.py +++ b/manim/animation/composition.py @@ -61,6 +61,8 @@ def __init__( lag_ratio: float = 0, **kwargs, ) -> None: + if len(animations) == 0: + raise ValueError("AnimationGroup must have at least one animation") self.animations = [prepare_animation(anim) for anim in animations] self.rate_func = rate_func self.group = group From 3d8f269ab611537df937de3359def7c384223343 Mon Sep 17 00:00:00 2001 From: MrDiver Date: Sat, 9 Dec 2023 23:40:59 +0100 Subject: [PATCH 2/8] Move error messages into Animation.begin() --- manim/animation/animation.py | 2 ++ manim/animation/composition.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/manim/animation/animation.py b/manim/animation/animation.py index ddacb37c6c..38e854f5fc 100644 --- a/manim/animation/animation.py +++ b/manim/animation/animation.py @@ -191,6 +191,8 @@ def begin(self) -> None: method. """ + if self.run_time == 0: + raise ValueError(f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! please set a runtime > 0") self.starting_mobject = self.create_starting_mobject() if self.suspend_mobject_updating: # All calls to self.mobject's internal updaters diff --git a/manim/animation/composition.py b/manim/animation/composition.py index 39770e8d4e..109c9379b5 100644 --- a/manim/animation/composition.py +++ b/manim/animation/composition.py @@ -61,8 +61,6 @@ def __init__( lag_ratio: float = 0, **kwargs, ) -> None: - if len(animations) == 0: - raise ValueError("AnimationGroup must have at least one animation") self.animations = [prepare_animation(anim) for anim in animations] self.rate_func = rate_func self.group = group @@ -83,6 +81,9 @@ def get_all_mobjects(self) -> Sequence[Mobject]: return list(self.group) def begin(self) -> None: + if self.run_time == 0: + tmp = "please set a runtime > 0" if len(self.animations) != 0 else "Please add at least one Animation" + raise ValueError(f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! {tmp}.") if self.suspend_mobject_updating: self.group.suspend_updating() for anim in self.animations: From 3c5bd82a6b70743847667baa830053d67c912a66 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 9 Dec 2023 22:41:49 +0000 Subject: [PATCH 3/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/animation/animation.py | 4 +++- manim/animation/composition.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/manim/animation/animation.py b/manim/animation/animation.py index 38e854f5fc..7b3944ce0b 100644 --- a/manim/animation/animation.py +++ b/manim/animation/animation.py @@ -192,7 +192,9 @@ def begin(self) -> None: """ if self.run_time == 0: - raise ValueError(f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! please set a runtime > 0") + raise ValueError( + f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! please set a runtime > 0" + ) self.starting_mobject = self.create_starting_mobject() if self.suspend_mobject_updating: # All calls to self.mobject's internal updaters diff --git a/manim/animation/composition.py b/manim/animation/composition.py index 109c9379b5..0cf4c62511 100644 --- a/manim/animation/composition.py +++ b/manim/animation/composition.py @@ -82,8 +82,14 @@ def get_all_mobjects(self) -> Sequence[Mobject]: def begin(self) -> None: if self.run_time == 0: - tmp = "please set a runtime > 0" if len(self.animations) != 0 else "Please add at least one Animation" - raise ValueError(f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! {tmp}.") + tmp = ( + "please set a runtime > 0" + if len(self.animations) != 0 + else "Please add at least one Animation" + ) + raise ValueError( + f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! {tmp}." + ) if self.suspend_mobject_updating: self.group.suspend_updating() for anim in self.animations: From 5fd208cbf92ee099d5ddbcbd0b5597007058e48f Mon Sep 17 00:00:00 2001 From: MrDiver Date: Sat, 9 Dec 2023 23:45:51 +0100 Subject: [PATCH 4/8] Added tests --- tests/module/animation/test_composition.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/module/animation/test_composition.py b/tests/module/animation/test_composition.py index 73cc6b0d60..54c8d623f3 100644 --- a/tests/module/animation/test_composition.py +++ b/tests/module/animation/test_composition.py @@ -169,3 +169,11 @@ def test_animationgroup_is_passing_remover_to_nested_animationgroups(): assert sqr_animation.remover assert circ_animation.remover assert polygon_animation.remover + +def test_empty_animation_group_fails(): + with pytest.raises(ValueError): + AnimationGroup().begin() + +def test_empty_animation_fails(): + with pytest.raises(ValueError): + FadeIn(None, run_time=0).begin() From de8a55d7220f1a1df0190d9fe9d831e87868985f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 9 Dec 2023 22:47:00 +0000 Subject: [PATCH 5/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/module/animation/test_composition.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/module/animation/test_composition.py b/tests/module/animation/test_composition.py index 54c8d623f3..1f6d6bf5c1 100644 --- a/tests/module/animation/test_composition.py +++ b/tests/module/animation/test_composition.py @@ -170,10 +170,12 @@ def test_animationgroup_is_passing_remover_to_nested_animationgroups(): assert circ_animation.remover assert polygon_animation.remover + def test_empty_animation_group_fails(): with pytest.raises(ValueError): AnimationGroup().begin() + def test_empty_animation_fails(): with pytest.raises(ValueError): FadeIn(None, run_time=0).begin() From fdc0ccdd0bbd5811d4b54628c696b47780b78d57 Mon Sep 17 00:00:00 2001 From: Tristan Schulz Date: Sun, 10 Dec 2023 03:17:54 +0100 Subject: [PATCH 6/8] Update manim/animation/animation.py --- manim/animation/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/animation/animation.py b/manim/animation/animation.py index 7b3944ce0b..d48ae655df 100644 --- a/manim/animation/animation.py +++ b/manim/animation/animation.py @@ -191,7 +191,7 @@ def begin(self) -> None: method. """ - if self.run_time == 0: + if self.run_time <= 0: raise ValueError( f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! please set a runtime > 0" ) From cfdc8c57487e2622aaf3dbc0ef45f002884eac81 Mon Sep 17 00:00:00 2001 From: Tristan Schulz Date: Sun, 10 Dec 2023 03:17:59 +0100 Subject: [PATCH 7/8] Update manim/animation/composition.py --- manim/animation/composition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/animation/composition.py b/manim/animation/composition.py index 0cf4c62511..20b23d828c 100644 --- a/manim/animation/composition.py +++ b/manim/animation/composition.py @@ -81,7 +81,7 @@ def get_all_mobjects(self) -> Sequence[Mobject]: return list(self.group) def begin(self) -> None: - if self.run_time == 0: + if self.run_time <= 0: tmp = ( "please set a runtime > 0" if len(self.animations) != 0 From d4621e42a53ef854fb51ec72d8eaf41beb611f20 Mon Sep 17 00:00:00 2001 From: Tristan Schulz Date: Sun, 10 Dec 2023 18:10:16 +0100 Subject: [PATCH 8/8] Update manim/animation/animation.py Co-authored-by: Jason Grace <110117391+JasonGrace2282@users.noreply.github.com> --- manim/animation/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/animation/animation.py b/manim/animation/animation.py index d48ae655df..75629ecb55 100644 --- a/manim/animation/animation.py +++ b/manim/animation/animation.py @@ -193,7 +193,7 @@ def begin(self) -> None: """ if self.run_time <= 0: raise ValueError( - f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! please set a runtime > 0" + f"{self} has a runtime of <= 0 seconds, which cannot be rendered correctly! please set a runtime > 0" ) self.starting_mobject = self.create_starting_mobject() if self.suspend_mobject_updating: