1212TEMPLATE_DATA = Path (__file__ ).parent / "test_data" / "map_tests" / "template"
1313
1414
15+ @pytest .mark .parametrize ("group_depth" , [0 , 1 , 3 ])
1516@pytest .mark .parametrize ("format_" , ["json" , "tmx" ])
1617@pytest .mark .parametrize ("with_map_tilesets" , [False , True ])
17- def test_template_tileset_allocation (tmp_path , format_ , with_map_tilesets ):
18+ def test_template_tileset_allocation (tmp_path , format_ , with_map_tilesets , group_depth ):
1819 source = TEMPLATE_DATA / ("map." + format_ )
1920 destination = tmp_path / source .name
2021 if format_ == "json" :
@@ -30,6 +31,20 @@ def test_template_tileset_allocation(tmp_path, format_, with_map_tilesets):
3031 objects [- 1 ]["id" ] = 8
3132 for object_ in objects :
3233 object_ ["template" ] = str ((TEMPLATE_DATA / object_ ["template" ]).resolve ())
34+ for depth in range (group_depth ):
35+ document ["layers" ] = [
36+ {
37+ "id" : 3 + depth ,
38+ "name" : "group" ,
39+ "type" : "group" ,
40+ "opacity" : 1 ,
41+ "visible" : True ,
42+ "x" : 0 ,
43+ "y" : 0 ,
44+ "layers" : document ["layers" ],
45+ }
46+ ]
47+ document ["nextlayerid" ] = 3 + group_depth
3348 destination .write_text (json .dumps (document ))
3449 else :
3550 document = etree .parse (source )
@@ -49,10 +64,20 @@ def test_template_tileset_allocation(tmp_path, format_, with_map_tilesets):
4964 object_ .set (
5065 "template" , str ((TEMPLATE_DATA / object_ .get ("template" )).resolve ())
5166 )
67+ document .getroot ().remove (layer )
68+ for depth in range (group_depth ):
69+ group = etree .Element ("group" , id = str (3 + depth ), name = "group" )
70+ group .append (layer )
71+ layer = group
72+ document .getroot ().append (layer )
73+ document .getroot ().set ("nextlayerid" , str (3 + group_depth ))
5274 document .write (destination , encoding = "utf-8" )
5375
5476 parsed = parse_map (destination )
55- objects = parsed .layers [0 ].tiled_objects
77+ layer = parsed .layers [0 ]
78+ for _ in range (group_depth ):
79+ layer = layer .layers [0 ]
80+ objects = layer .tiled_objects
5681 expected_gids = [49 , 50 , 49 ] if with_map_tilesets else [1 , 2 , 1 ]
5782 assert [object_ .gid for object_ in objects [1 :]] == expected_gids
5883 assert sorted (parsed .tilesets ) == ([1 , 49 , 50 ] if with_map_tilesets else [1 , 2 ])
0 commit comments