3
3
import numpy as np
4
4
import pytest
5
5
6
- from manim import Circle , Line , Square , VDict , VGroup
6
+ from manim import Circle , Line , Square , VDict , VGroup , VMobject
7
7
from manim .mobject .opengl .opengl_mobject import OpenGLMobject
8
8
from manim .mobject .opengl .opengl_vectorized_mobject import OpenGLVMobject
9
9
@@ -90,26 +90,84 @@ def test_vgroup_init(using_opengl_renderer):
90
90
VGroup (3.0 )
91
91
assert str (init_with_float_info .value ) == (
92
92
"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."
94
94
)
95
95
96
96
with pytest .raises (TypeError ) as init_with_mob_info :
97
97
VGroup (OpenGLMobject ())
98
98
assert str (init_with_mob_info .value ) == (
99
99
"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 "
101
101
"OpenGLMobject. You can try adding this value into a Group instead."
102
102
)
103
103
104
104
with pytest .raises (TypeError ) as init_with_vmob_and_mob_info :
105
105
VGroup (OpenGLVMobject (), OpenGLMobject ())
106
106
assert str (init_with_vmob_and_mob_info .value ) == (
107
107
"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 "
109
109
"OpenGLMobject. You can try adding this value into a Group instead."
110
110
)
111
111
112
112
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
+
113
171
def test_vgroup_add (using_opengl_renderer ):
114
172
"""Test the VGroup add method."""
115
173
obj = VGroup ()
@@ -123,7 +181,7 @@ def test_vgroup_add(using_opengl_renderer):
123
181
obj .add (3 )
124
182
assert str (add_int_info .value ) == (
125
183
"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."
127
185
)
128
186
assert len (obj .submobjects ) == 1
129
187
@@ -133,7 +191,7 @@ def test_vgroup_add(using_opengl_renderer):
133
191
obj .add (OpenGLMobject ())
134
192
assert str (add_mob_info .value ) == (
135
193
"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 "
137
195
"OpenGLMobject. You can try adding this value into a Group instead."
138
196
)
139
197
assert len (obj .submobjects ) == 1
@@ -143,7 +201,7 @@ def test_vgroup_add(using_opengl_renderer):
143
201
obj .add (OpenGLVMobject (), OpenGLMobject ())
144
202
assert str (add_vmob_and_mob_info .value ) == (
145
203
"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 "
147
205
"OpenGLMobject. You can try adding this value into a Group instead."
148
206
)
149
207
assert len (obj .submobjects ) == 1
0 commit comments