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: Fixed a bug in regards to empty inputs in AddTextLetterByLetter class. #3404

Merged
merged 17 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b9d2377
Misc: Just a class to test out some functions
Immanuel-Alvaro-Bhirawa Oct 10, 2023
73b6d07
Merge branch 'main' of https://github.com/Immanuel-Alvaro-Bhirawa/manim
Immanuel-Alvaro-Bhirawa Oct 10, 2023
cdd4903
Fix: Fixed a bug in AddTextLetterByLetter class
Immanuel-Alvaro-Bhirawa Oct 14, 2023
b89ffcc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2023
37698f0
Merge branch 'main' into main
Immanuel-Alvaro-Bhirawa Oct 14, 2023
e3f95db
Fix: Adjusted changes according to Ben's comments
Immanuel-Alvaro-Bhirawa Oct 18, 2023
db1fc4f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2023
d3f0a10
Fix: Removed imports
Immanuel-Alvaro-Bhirawa Oct 18, 2023
d1cc590
Merge branch 'main' of https://github.com/Immanuel-Alvaro-Bhirawa/manim
Immanuel-Alvaro-Bhirawa Oct 18, 2023
2b8bf5b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2023
42b2cb8
Merge branch 'main' into main
Immanuel-Alvaro-Bhirawa Oct 25, 2023
1159f65
Feat: Adjusted changes to AddTextLetterByLetter
Immanuel-Alvaro-Bhirawa Oct 25, 2023
72256fd
Merge branch 'main' of https://github.com/Immanuel-Alvaro-Bhirawa/manim
Immanuel-Alvaro-Bhirawa Oct 25, 2023
0c7ee00
Merge branch 'main' into main
behackl Oct 25, 2023
9d69ce2
Merge branch 'main' of https://github.com/Immanuel-Alvaro-Bhirawa/manim
Immanuel-Alvaro-Bhirawa Oct 25, 2023
0b442a2
Feat: Added test_creation
Immanuel-Alvaro-Bhirawa Oct 25, 2023
b638927
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions manim/animation/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ def __init__(
**kwargs,
) -> None:
self.time_per_char = time_per_char
# Check for empty text using family_members_with_points()
if not text.family_members_with_points():
raise ValueError(
f"The text mobject {text} does not seem to contain any characters."
)
if run_time is None:
# minimum time per character is 1/frame_rate, otherwise
# the animation does not finish.
Expand Down
34 changes: 34 additions & 0 deletions tests/module/animation/test_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import annotations

import numpy as np
import pytest

from manim import AddTextLetterByLetter, Text, config


def test_non_empty_text_creation():
"""Check if AddTextLetterByLetter works for non-empty text."""
s = Text("Hello")
anim = AddTextLetterByLetter(s)
assert anim.mobject.text == "Hello"


def test_empty_text_creation():
"""Ensure ValueError is raised for empty text."""
with pytest.raises(ValueError, match="does not seem to contain any characters"):
AddTextLetterByLetter(Text(""))


def test_whitespace_text_creation():
"""Ensure ValueError is raised for whitespace-only text, assuming the whitespace characters have no points."""
with pytest.raises(ValueError, match="does not seem to contain any characters"):
AddTextLetterByLetter(Text(" "))


def test_run_time_for_non_empty_text():
"""Ensure the run_time is calculated correctly for non-empty text."""
s = Text("Hello")
run_time_per_char = 0.1
expected_run_time = np.max((1 / config.frame_rate, run_time_per_char)) * len(s.text)
anim = AddTextLetterByLetter(s, time_per_char=run_time_per_char)
assert anim.run_time == expected_run_time
Loading