Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

fix: proper VGroup pluralizing of "submobject(s)" (#4950)

nikolajmunk0204c66ab6fe
diff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.py
index 5c3958616..517f8accd 100644
--- a/manim/mobject/opengl/opengl_vectorized_mobject.py
+++ b/manim/mobject/opengl/opengl_vectorized_mobject.py
@@ -1704,10 +1704,10 @@ class OpenGLVGroup(OpenGLVMobject):
+ ")"
)
- def __str__(self):
+ def __str__(self) -> str:
return (
f"{self.__class__.__name__} of {len(self.submobjects)} "
- f"submobject{'s' if len(self.submobjects) > 0 else ''}"
+ f"submobject{'' if len(self.submobjects) == 1 else 's'}"
)
def add(self, *vmobjects: OpenGLVMobject) -> Self:
diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py
index 791b28bf5..8d0526853 100644
--- a/manim/mobject/types/vectorized_mobject.py
+++ b/manim/mobject/types/vectorized_mobject.py
@@ -2249,7 +2249,7 @@ class VGroup(VMobject, metaclass=ConvertToOpenGL):
def __str__(self) -> str:
return (
f"{self.__class__.__name__} of {len(self.submobjects)} "
- f"submobject{'s' if len(self.submobjects) > 0 else ''}"
+ f"submobject{'' if len(self.submobjects) == 1 else 's'}"
)
def add(
diff --git a/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py b/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py
index f92d1ac6e..8881a26d9 100644
--- a/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py
+++ b/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py
@@ -452,6 +452,28 @@ def test_vgroup_item_assignment_only_allows_vmobjects():
)
+def test_vgroup_str_name():
+ """Test VGroup's string representation correctly includes class name"""
+
+ class VGroupSubclass(VGroup):
+ pass
+
+ for cls, name in (VGroup, "VGroup"), (VGroupSubclass, "VGroupSubclass"):
+ group = cls(VMobject())
+ expected = f"{name} of"
+ actual = str(group)
+ assert actual.startswith(expected), f"'{actual}'.startswith('{expected}')"
+
+
+def test_vgroup_str_pluralization():
+ """Test VGroup's string representation correctly pluralizes 'submobject(s)'"""
+ for i in (0, 1, 2):
+ group = VGroup(VMobject() for _ in range(i))
+ expected = f"of {i} {'submobject' if i == 1 else 'submobjects'}"
+ actual = str(group)
+ assert actual.endswith(expected), f"'{actual}'.endswith('{expected}')"
+
+
def test_trim_dummy():
o = VMobject()
o.start_new_path(np.array([0, 0, 0]))
diff --git a/tests/opengl/test_opengl_vectorized_mobject.py b/tests/opengl/test_opengl_vectorized_mobject.py
index db86c4dbf..6cdc3d3c2 100644
--- a/tests/opengl/test_opengl_vectorized_mobject.py
+++ b/tests/opengl/test_opengl_vectorized_mobject.py
@@ -372,3 +372,25 @@ def test_vgroup_item_assignment_only_allows_vmobjects(using_opengl_renderer):
"Only values of type OpenGLVMobject can be added as submobjects of "
"VGroup, but the value invalid object (at index 0) is of type str."
)
+
+
+def test_vgroup_str_name(using_opengl_renderer):
+ """Test VGroup's string representation correctly includes class name"""
+
+ class VGroupSubclass(VGroup):
+ pass
+
+ for cls, name in (VGroup, "VGroup"), (VGroupSubclass, "VGroupSubclass"):
+ group = cls(OpenGLVMobject())
+ expected = f"{name} of"
+ actual = str(group)
+ assert actual.startswith(expected), f"'{actual}'.startswith('{expected}')"
+
+
+def test_vgroup_str_pluralization(using_opengl_renderer):
+ """Test VGroup's string representation correctly pluralizes 'submobject(s)'"""
+ for i in (0, 1, 2):
+ group = VGroup(OpenGLVMobject() for _ in range(i))
+ expected = f"of {i} {'submobject' if i == 1 else 'submobjects'}"
+ actual = str(group)
+ assert actual.endswith(expected), f"'{actual}'.endswith('{expected}')"