Skip to content

Commit

Permalink
Initial object template tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cleptomania committed May 16, 2021
1 parent fec4064 commit e2573ff
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/test_data/map_tests/template/expected.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from pathlib import Path

from pytiled_parser import common_types, layer, tiled_map, tiled_object, tileset

EXPECTED = tiled_map.TiledMap(
infinite=False,
layers=[
layer.ObjectLayer(
name="Object Layer 1",
opacity=1,
visible=True,
id=2,
draw_order="topdown",
tiled_objects=[
tiled_object.Rectangle(
id=2,
name="",
rotation=0,
size=common_types.Size(63.6585878103079, 38.2811778048473),
coordinates=common_types.OrderedPair(
98.4987608686521, 46.2385012811358
),
visible=True,
type="",
),
tiled_object.Tile(
id=3,
coordinates=common_types.OrderedPair(
46.3682110303692, 112.993321292057
),
name="",
rotation=0,
type="",
visible=True,
size=common_types.Size(32, 32),
gid=30,
),
],
)
],
map_size=common_types.Size(8, 6),
next_layer_id=3,
next_object_id=4,
orientation="orthogonal",
render_order="right-down",
tiled_version="1.6.0",
tile_size=common_types.Size(32, 32),
version="1.6",
background_color=common_types.Color(255, 0, 4, 255),
tilesets={
1: tileset.Tileset(
columns=8,
image=Path(Path(__file__).parent / "../../images/tmw_desert_spacing.png")
.absolute()
.resolve(),
image_width=265,
image_height=199,
margin=1,
spacing=1,
name="tile_set_image",
tile_count=48,
tiled_version="1.6.0",
tile_height=32,
tile_width=32,
version="1.6",
type="tileset",
)
},
properties={
"bool property - true": True,
"color property": common_types.Color(255, 73, 252, 255),
"file property": Path("../../../../../../var/log/syslog"),
"float property": 1.23456789,
"int property": 13,
"string property": "Hello, World!!",
},
)
75 changes: 75 additions & 0 deletions tests/test_data/map_tests/template/map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{ "backgroundcolor":"#ff0004",
"compressionlevel":0,
"height":6,
"infinite":false,
"layers":[
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[
{
"id":2,
"template":"template.json",
"x":98.4987608686521,
"y":46.2385012811358
},
{
"id":3,
"template":"template_tile.json",
"x":46.3682110303692,
"y":112.993321292057
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":3,
"nextobjectid":4,
"orientation":"orthogonal",
"properties":[
{
"name":"bool property - true",
"type":"bool",
"value":true
},
{
"name":"color property",
"type":"color",
"value":"#ff49fcff"
},
{
"name":"file property",
"type":"file",
"value":"..\/..\/..\/..\/..\/..\/var\/log\/syslog"
},
{
"name":"float property",
"type":"float",
"value":1.23456789
},
{
"name":"int property",
"type":"int",
"value":13
},
{
"name":"string property",
"type":"string",
"value":"Hello, World!!"
}],
"renderorder":"right-down",
"tiledversion":"1.6.0",
"tileheight":32,
"tilesets":[
{
"firstgid":1,
"source":"tileset.json"
}],
"tilewidth":32,
"type":"map",
"version":"1.6",
"width":8
}
12 changes: 12 additions & 0 deletions tests/test_data/map_tests/template/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ "object":
{
"height":38.2811778048473,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":63.6585878103079
},
"type":"template"
}
18 changes: 18 additions & 0 deletions tests/test_data/map_tests/template/template_tile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ "object":
{
"gid":30,
"height":32,
"id":3,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":32
},
"tileset":
{
"firstgid":1,
"source":"tileset.json"
},
"type":"template"
}
14 changes: 14 additions & 0 deletions tests/test_data/map_tests/template/tileset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ "columns":8,
"image":"..\/..\/images\/tmw_desert_spacing.png",
"imageheight":199,
"imagewidth":265,
"margin":1,
"name":"tile_set_image",
"spacing":1,
"tilecount":48,
"tiledversion":"1.6.0",
"tileheight":32,
"tilewidth":32,
"type":"tileset",
"version":"1.6"
}
1 change: 1 addition & 0 deletions tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
MAP_TESTS / "no_background_color",
MAP_TESTS / "hexagonal",
MAP_TESTS / "embedded_tileset",
MAP_TESTS / "template",
]


Expand Down
16 changes: 16 additions & 0 deletions tests/test_tiled_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,3 +1103,19 @@ def test_parse_layer(raw_object_json, expected):
result = tiled_object.cast(raw_object)

assert result == expected


def test_parse_no_parent_dir():

raw_object = """
{
"id":1,
"template": "mytemplate.json",
"x":27.7185404115039,
"y":23.571672160964
}
"""

json_object = json.loads(raw_object)
with pytest.raises(RuntimeError):
tiled_object.cast(json_object)

0 comments on commit e2573ff

Please sign in to comment.