@@ -124,3 +124,66 @@ def test_scene_serialisation_empty():
124124 scene = compas .json_loads (compas .json_dumps (scene ))
125125
126126 assert isinstance (scene , Scene )
127+
128+ def test_group_serialisation ():
129+ scene1 = Scene ()
130+ group = scene1 .add_group ("TestGroup" , show = False )
131+ box = Box .from_width_height_depth (1 , 1 , 1 )
132+ group .add (box )
133+
134+ scene2 = Scene .from_jsonstring (scene1 .to_jsonstring ())
135+
136+ # Check if group was serialized correctly
137+ group2 = scene2 .find_by_name ("TestGroup" )
138+ assert isinstance (group2 , Group )
139+ assert group2 .name == "TestGroup"
140+ assert not group2 .show
141+
142+ # Check if box was serialized correctly
143+ box2 = group2 .children [0 ]
144+ assert isinstance (box2 .item , Box )
145+ assert box2 .parent is group2
146+
147+ def test_nested_group_serialisation ():
148+ scene1 = Scene ()
149+ parent_group = scene1 .add_group ("ParentGroup" , show = False )
150+ child_group = parent_group .add (Group ("ChildGroup" , show = True ))
151+ box = Box .from_width_height_depth (1 , 1 , 1 )
152+ child_group .add (box )
153+
154+ scene2 = Scene .from_jsonstring (scene1 .to_jsonstring ())
155+
156+ # Check parent group
157+ parent2 = scene2 .find_by_name ("ParentGroup" )
158+ assert isinstance (parent2 , Group )
159+ assert not parent2 .show
160+
161+ # Check child group
162+ child2 = parent2 .children [0 ]
163+ assert isinstance (child2 , Group )
164+ assert child2 .name == "ChildGroup"
165+ assert child2 .show
166+ assert child2 .parent is parent2
167+
168+ # Check box
169+ box2 = child2 .children [0 ]
170+ assert isinstance (box2 .item , Box )
171+ assert box2 .parent is child2
172+
173+ def test_group_kwargs_serialisation ():
174+ scene1 = Scene ()
175+ group = scene1 .add_group ("TestGroup" , show = False , opacity = 0.5 )
176+ box = Box .from_width_height_depth (1 , 1 , 1 )
177+ group .add (box )
178+
179+ scene2 = Scene .from_jsonstring (scene1 .to_jsonstring ())
180+
181+ # Check if group kwargs were serialized correctly
182+ group2 = scene2 .find_by_name ("TestGroup" )
183+ assert not group2 .show
184+ assert group2 .opacity == 0.5
185+
186+ # Check if box inherited kwargs correctly
187+ box2 = group2 .children [0 ]
188+ assert not box2 .show
189+ assert box2 .opacity == 0.5
0 commit comments