A community-maintained Python framework for creating mathematical animations.
Fix: Fixed a bug in regards to empty inputs in AddTextLetterByLetter class. (#3404)
Immanuel-Alvaro-Bhirawa76b4061aa6d8
diff --git a/manim/animation/creation.py b/manim/animation/creation.pyindex a2e7f8a36..f28c12302 100644--- a/manim/animation/creation.py+++ b/manim/animation/creation.py@@ -563,6 +563,11 @@ class AddTextLetterByLetter(ShowIncreasingSubsets):**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.diff --git a/tests/module/animation/test_creation.py b/tests/module/animation/test_creation.pynew file mode 100644index 000000000..3208ad1b4--- /dev/null+++ b/tests/module/animation/test_creation.py@@ -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