tests(layer): Base64 with uncompressed, gzip, and zlib type tests.

This commit is contained in:
Darren Eberly
2020-07-27 20:57:18 -04:00
parent 67514eed71
commit 7211a14c98
14 changed files with 407 additions and 204 deletions

View File

@@ -209,7 +209,7 @@ def _decode_tile_layer_data(tile_layer: TileLayer) -> TileLayer:
unzipped_data = zlib.decompress(unencoded_data)
elif tile_layer.compression == "gzip":
unzipped_data = gzip.decompress(unencoded_data)
elif tile_layer.compression is None:
elif not tile_layer.compression:
unzipped_data = unencoded_data
else:
raise ValueError(f"Unsupported compression type: '{tile_layer.compression}'.")
@@ -228,7 +228,6 @@ def _decode_tile_layer_data(tile_layer: TileLayer) -> TileLayer:
tile_grid.append(int_value)
int_value = 0
tile_grid.pop()
tile_layer.data = tile_grid
return tile_layer

View File

@@ -1,11 +1,4 @@
{ "compressionlevel":-1,
"editorsettings":
{
"export":
{
"target":"."
}
},
"height":6,
"infinite":false,
"layers":[

View File

@@ -1,3 +1,99 @@
from pytiled_parser import common_types, layer
from pathlib import Path
EXPECTED = [layer.TileLayer(name="Tile Layer 1", opacity=1, visible=True)]
from pytiled_parser import common_types, layer, tiled_object
EXPECTED = [
layer.TileLayer(
name="Tile Layer 1",
opacity=1,
visible=True,
id=1,
size=common_types.Size(8, 6),
encoding="base64",
compression="",
data=[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
],
),
layer.LayerGroup(
name="Group 1",
opacity=1,
visible=True,
id=4,
layers=[
layer.ObjectLayer(
name="Object Layer 1",
opacity=1,
visible=True,
id=2,
draw_order="topdown",
tiled_objects=[
tiled_object.Rectangle(
id=1,
name="",
rotation=0,
size=common_types.Size(69.3333333333333, 52.6666666666667),
coordinates=common_types.OrderedPair(46.3333333333333, 39),
visible=True,
type="",
)
],
),
],
),
layer.ImageLayer(
name="Image Layer 1",
opacity=1,
visible=True,
id=3,
image=Path("../../images/tile_04.png"),
transparent_color=common_types.Color("#000000"),
),
]

View File

@@ -1,11 +1,4 @@
{ "compressionlevel":-1,
"editorsettings":
{
"export":
{
"target":"."
}
},
"height":6,
"infinite":false,
"layers":[
@@ -23,39 +16,51 @@
"x":0,
"y":0
},
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
{
"id":3,
"image":"",
"name":"Image Layer 1",
"opacity":1,
"type":"imagelayer",
"visible":true,
"x":0,
"y":0
},
{
"id":4,
"layers":[],
"layers":[
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[
{
"height":52.6666666666667,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":69.3333333333333,
"x":46.3333333333333,
"y":39
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"name":"Group 1",
"opacity":1,
"type":"group",
"visible":true,
"x":0,
"y":0
},
{
"id":3,
"image":"..\/..\/images\/tile_04.png",
"name":"Image Layer 1",
"opacity":1,
"transparentcolor":"#000000",
"type":"imagelayer",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":5,
"nextobjectid":1,
"nextobjectid":3,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.4.1",
@@ -63,7 +68,7 @@
"tilesets":[
{
"firstgid":1,
"source":"tileset.json"
"source":"..\/all_layer_types\/tileset.json"
}],
"tilewidth":32,
"type":"map",

View File

@@ -1,3 +1,99 @@
from pytiled_parser import common_types, layer
from pathlib import Path
EXPECTED = [layer.TileLayer(name="Tile Layer 1", opacity=1, visible=True)]
from pytiled_parser import common_types, layer, tiled_object
EXPECTED = [
layer.TileLayer(
name="Tile Layer 1",
opacity=1,
visible=True,
id=1,
size=common_types.Size(8, 6),
encoding="base64",
compression="gzip",
data=[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
],
),
layer.LayerGroup(
name="Group 1",
opacity=1,
visible=True,
id=4,
layers=[
layer.ObjectLayer(
name="Object Layer 1",
opacity=1,
visible=True,
id=2,
draw_order="topdown",
tiled_objects=[
tiled_object.Rectangle(
id=1,
name="",
rotation=0,
size=common_types.Size(69.3333333333333, 52.6666666666667),
coordinates=common_types.OrderedPair(46.3333333333333, 39),
visible=True,
type="",
)
],
),
],
),
layer.ImageLayer(
name="Image Layer 1",
opacity=1,
visible=True,
id=3,
image=Path("../../images/tile_04.png"),
transparent_color=common_types.Color("#000000"),
),
]

View File

@@ -1,11 +1,4 @@
{ "compressionlevel":-1,
"editorsettings":
{
"export":
{
"target":"."
}
},
"height":6,
"infinite":false,
"layers":[
@@ -23,39 +16,51 @@
"x":0,
"y":0
},
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
{
"id":3,
"image":"",
"name":"Image Layer 1",
"opacity":1,
"type":"imagelayer",
"visible":true,
"x":0,
"y":0
},
{
"id":4,
"layers":[],
"layers":[
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[
{
"height":52.6666666666667,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":69.3333333333333,
"x":46.3333333333333,
"y":39
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"name":"Group 1",
"opacity":1,
"type":"group",
"visible":true,
"x":0,
"y":0
},
{
"id":3,
"image":"..\/..\/images\/tile_04.png",
"name":"Image Layer 1",
"opacity":1,
"transparentcolor":"#000000",
"type":"imagelayer",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":5,
"nextobjectid":1,
"nextobjectid":3,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.4.1",
@@ -63,7 +68,7 @@
"tilesets":[
{
"firstgid":1,
"source":"tileset.json"
"source":"..\/all_layer_types\/tileset.json"
}],
"tilewidth":32,
"type":"map",

View File

@@ -1,3 +0,0 @@
from pytiled_parser import common_types, layer
EXPECTED = [layer.TileLayer(name="Tile Layer 1", opacity=1, visible=True)]

View File

@@ -0,0 +1,99 @@
from pathlib import Path
from pytiled_parser import common_types, layer, tiled_object
EXPECTED = [
layer.TileLayer(
name="Tile Layer 1",
opacity=1,
visible=True,
id=1,
size=common_types.Size(8, 6),
encoding="base64",
compression="zlib",
data=[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
],
),
layer.LayerGroup(
name="Group 1",
opacity=1,
visible=True,
id=4,
layers=[
layer.ObjectLayer(
name="Object Layer 1",
opacity=1,
visible=True,
id=2,
draw_order="topdown",
tiled_objects=[
tiled_object.Rectangle(
id=1,
name="",
rotation=0,
size=common_types.Size(69.3333333333333, 52.6666666666667),
coordinates=common_types.OrderedPair(46.3333333333333, 39),
visible=True,
type="",
)
],
),
],
),
layer.ImageLayer(
name="Image Layer 1",
opacity=1,
visible=True,
id=3,
image=Path("../../images/tile_04.png"),
transparent_color=common_types.Color("#000000"),
),
]

View File

@@ -1,11 +1,4 @@
{ "compressionlevel":-1,
"editorsettings":
{
"export":
{
"target":"."
}
},
"height":6,
"infinite":false,
"layers":[
@@ -23,39 +16,51 @@
"x":0,
"y":0
},
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
{
"id":3,
"image":"",
"name":"Image Layer 1",
"opacity":1,
"type":"imagelayer",
"visible":true,
"x":0,
"y":0
},
{
"id":4,
"layers":[],
"layers":[
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[
{
"height":52.6666666666667,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":69.3333333333333,
"x":46.3333333333333,
"y":39
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"name":"Group 1",
"opacity":1,
"type":"group",
"visible":true,
"x":0,
"y":0
},
{
"id":3,
"image":"..\/..\/images\/tile_04.png",
"name":"Image Layer 1",
"opacity":1,
"transparentcolor":"#000000",
"type":"imagelayer",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":5,
"nextobjectid":1,
"nextobjectid":3,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.4.1",
@@ -63,7 +68,7 @@
"tilesets":[
{
"firstgid":1,
"source":"tileset.json"
"source":"..\/all_layer_types\/tileset.json"
}],
"tilewidth":32,
"type":"map",

View File

@@ -1,3 +0,0 @@
from pytiled_parser import common_types, layer
EXPECTED = [layer.TileLayer(name="Tile Layer 1", opacity=1, visible=True)]

View File

@@ -1,70 +0,0 @@
{ "compressionlevel":-1,
"editorsettings":
{
"export":
{
"target":"."
}
},
"height":6,
"infinite":false,
"layers":[
{
"data":[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48],
"height":6,
"id":1,
"name":"Tile Layer 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":8,
"x":0,
"y":0
},
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
{
"id":3,
"image":"",
"name":"Image Layer 1",
"opacity":1,
"type":"imagelayer",
"visible":true,
"x":0,
"y":0
},
{
"id":4,
"layers":[],
"name":"Group 1",
"opacity":1,
"type":"group",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":5,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.4.1",
"tileheight":32,
"tilesets":[
{
"firstgid":1,
"source":"tileset.json"
}],
"tilewidth":32,
"type":"map",
"version":1.4,
"width":8
}

View File

@@ -1,22 +0,0 @@
{ "columns":8,
"editorsettings":
{
"export":
{
"format":"",
"target":"."
}
},
"image":"..\/..\/images\/tmw_desert_spacing.png",
"imageheight":199,
"imagewidth":265,
"margin":1,
"name":"tile_set_image",
"spacing":1,
"tilecount":48,
"tiledversion":"1.3.5",
"tileheight":32,
"tilewidth":32,
"type":"tileset",
"version":1.2
}

View File

@@ -15,6 +15,9 @@ LAYER_TESTS = TEST_DATA / "layer_tests"
ALL_LAYER_TESTS = [
LAYER_TESTS / "all_layer_types",
LAYER_TESTS / "b64",
LAYER_TESTS / "b64_gzip",
LAYER_TESTS / "b64_zlib",
]