33import numpy as np
44import pytest
55
6- from manim import Circle , Line , Square , VDict , VGroup
6+ from manim import Circle , Line , Square , VDict , VGroup , VMobject
77from manim .mobject .opengl .opengl_mobject import OpenGLMobject
88from manim .mobject .opengl .opengl_vectorized_mobject import OpenGLVMobject
99
@@ -90,26 +90,84 @@ def test_vgroup_init(using_opengl_renderer):
9090 VGroup (3.0 )
9191 assert str (init_with_float_info .value ) == (
9292 "Only values of type OpenGLVMobject can be added as submobjects of "
93- "VGroup, but the value 3.0 (at index 0) is of type float."
93+ "VGroup, but the value 3.0 (at index 0 of parameter 0 ) is of type float."
9494 )
9595
9696 with pytest .raises (TypeError ) as init_with_mob_info :
9797 VGroup (OpenGLMobject ())
9898 assert str (init_with_mob_info .value ) == (
9999 "Only values of type OpenGLVMobject can be added as submobjects of "
100- "VGroup, but the value OpenGLMobject (at index 0) is of type "
100+ "VGroup, but the value OpenGLMobject (at index 0 of parameter 0 ) is of type "
101101 "OpenGLMobject. You can try adding this value into a Group instead."
102102 )
103103
104104 with pytest .raises (TypeError ) as init_with_vmob_and_mob_info :
105105 VGroup (OpenGLVMobject (), OpenGLMobject ())
106106 assert str (init_with_vmob_and_mob_info .value ) == (
107107 "Only values of type OpenGLVMobject can be added as submobjects of "
108- "VGroup, but the value OpenGLMobject (at index 1) is of type "
108+ "VGroup, but the value OpenGLMobject (at index 0 of parameter 1) is of type "
109109 "OpenGLMobject. You can try adding this value into a Group instead."
110110 )
111111
112112
113+ def test_vgroup_init_with_iterable (using_opengl_renderer ):
114+ """Test VGroup instantiation with an iterable type."""
115+
116+ def type_generator (type_to_generate , n ):
117+ return (type_to_generate () for _ in range (n ))
118+
119+ def mixed_type_generator (major_type , minor_type , minor_type_positions , n ):
120+ return (
121+ minor_type () if i in minor_type_positions else major_type ()
122+ for i in range (n )
123+ )
124+
125+ obj = VGroup (OpenGLVMobject ())
126+ assert len (obj .submobjects ) == 1
127+
128+ obj = VGroup (type_generator (OpenGLVMobject , 38 ))
129+ assert len (obj .submobjects ) == 38
130+
131+ obj = VGroup (
132+ OpenGLVMobject (),
133+ [OpenGLVMobject (), OpenGLVMobject ()],
134+ type_generator (OpenGLVMobject , 38 ),
135+ )
136+ assert len (obj .submobjects ) == 41
137+
138+ # A VGroup cannot be initialised with an iterable containing a OpenGLMobject
139+ with pytest .raises (TypeError ) as init_with_mob_iterable :
140+ VGroup (type_generator (OpenGLMobject , 5 ))
141+ assert str (init_with_mob_iterable .value ) == (
142+ "Only values of type OpenGLVMobject can be added as submobjects of VGroup, "
143+ "but the value OpenGLMobject (at index 0 of parameter 0) is of type OpenGLMobject."
144+ )
145+
146+ # A VGroup cannot be initialised with an iterable containing a OpenGLMobject in any position
147+ with pytest .raises (TypeError ) as init_with_mobs_and_vmobs_iterable :
148+ VGroup (mixed_type_generator (OpenGLVMobject , OpenGLMobject , [3 , 5 ], 7 ))
149+ assert str (init_with_mobs_and_vmobs_iterable .value ) == (
150+ "Only values of type OpenGLVMobject can be added as submobjects of VGroup, "
151+ "but the value OpenGLMobject (at index 3 of parameter 0) is of type OpenGLMobject."
152+ )
153+
154+ # A VGroup cannot be initialised with an iterable containing non OpenGLVMobject's in any position
155+ with pytest .raises (TypeError ) as init_with_float_and_vmobs_iterable :
156+ VGroup (mixed_type_generator (OpenGLVMobject , float , [6 , 7 ], 9 ))
157+ assert str (init_with_float_and_vmobs_iterable .value ) == (
158+ "Only values of type OpenGLVMobject can be added as submobjects of VGroup, "
159+ "but the value 0.0 (at index 6 of parameter 0) is of type float."
160+ )
161+
162+ # A VGroup cannot be initialised with an iterable containing both OpenGLVMobject's and VMobject's
163+ with pytest .raises (TypeError ) as init_with_mobs_and_vmobs_iterable :
164+ VGroup (mixed_type_generator (OpenGLVMobject , VMobject , [3 , 5 ], 7 ))
165+ assert str (init_with_mobs_and_vmobs_iterable .value ) == (
166+ "Only values of type OpenGLVMobject can be added as submobjects of VGroup, "
167+ "but the value VMobject (at index 3 of parameter 0) is of type VMobject."
168+ )
169+
170+
113171def test_vgroup_add (using_opengl_renderer ):
114172 """Test the VGroup add method."""
115173 obj = VGroup ()
@@ -123,7 +181,7 @@ def test_vgroup_add(using_opengl_renderer):
123181 obj .add (3 )
124182 assert str (add_int_info .value ) == (
125183 "Only values of type OpenGLVMobject can be added as submobjects of "
126- "VGroup, but the value 3 (at index 0) is of type int."
184+ "VGroup, but the value 3 (at index 0 of parameter 0 ) is of type int."
127185 )
128186 assert len (obj .submobjects ) == 1
129187
@@ -133,7 +191,7 @@ def test_vgroup_add(using_opengl_renderer):
133191 obj .add (OpenGLMobject ())
134192 assert str (add_mob_info .value ) == (
135193 "Only values of type OpenGLVMobject can be added as submobjects of "
136- "VGroup, but the value OpenGLMobject (at index 0) is of type "
194+ "VGroup, but the value OpenGLMobject (at index 0 of parameter 0 ) is of type "
137195 "OpenGLMobject. You can try adding this value into a Group instead."
138196 )
139197 assert len (obj .submobjects ) == 1
@@ -143,7 +201,7 @@ def test_vgroup_add(using_opengl_renderer):
143201 obj .add (OpenGLVMobject (), OpenGLMobject ())
144202 assert str (add_vmob_and_mob_info .value ) == (
145203 "Only values of type OpenGLVMobject can be added as submobjects of "
146- "VGroup, but the value OpenGLMobject (at index 1) is of type "
204+ "VGroup, but the value OpenGLMobject (at index 0 of parameter 1) is of type "
147205 "OpenGLMobject. You can try adding this value into a Group instead."
148206 )
149207 assert len (obj .submobjects ) == 1
0 commit comments