Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix animations with zero runtime length to give a useful error instead of a broken pipe #3491

Merged
merged 10 commits into from
Dec 12, 2023
4 changes: 4 additions & 0 deletions manim/animation/animation.py
MrDiver marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ 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
Expand Down
9 changes: 9 additions & 0 deletions manim/animation/composition.py
MrDiver marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"please set a runtime > 0"
"Please set a positive run_time"

if len(self.animations) != 0
else "Please add at least one Animation"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else "Please add at least one Animation"
else "Please add at least one Animation with positive run_time"

)
raise ValueError(
f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! {tmp}."
MrDiver marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! {tmp}."
f"{self} has a run_time of 0 seconds, this cannot be rendered correctly. {tmp}."

)
if self.suspend_mobject_updating:
self.group.suspend_updating()
for anim in self.animations:
Expand Down
10 changes: 10 additions & 0 deletions tests/module/animation/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,13 @@ 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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="Please add at least one Animation"):

AnimationGroup().begin()
MrDiver marked this conversation as resolved.
Show resolved Hide resolved


def test_empty_animation_fails():
with pytest.raises(ValueError):
FadeIn(None, run_time=0).begin()
Loading