From e2573ff65580ab84786a981dbca00d76805bfbb1 Mon Sep 17 00:00:00 2001 From: Darren Eberly Date: Sun, 16 May 2021 00:40:48 -0400 Subject: [PATCH] Initial object template tests --- .../test_data/map_tests/template/expected.py | 77 +++++++++++++++++++ tests/test_data/map_tests/template/map.json | 75 ++++++++++++++++++ .../map_tests/template/template.json | 12 +++ .../map_tests/template/template_tile.json | 18 +++++ .../test_data/map_tests/template/tileset.json | 14 ++++ tests/test_map.py | 1 + tests/test_tiled_object.py | 16 ++++ 7 files changed, 213 insertions(+) create mode 100644 tests/test_data/map_tests/template/expected.py create mode 100644 tests/test_data/map_tests/template/map.json create mode 100644 tests/test_data/map_tests/template/template.json create mode 100644 tests/test_data/map_tests/template/template_tile.json create mode 100644 tests/test_data/map_tests/template/tileset.json diff --git a/tests/test_data/map_tests/template/expected.py b/tests/test_data/map_tests/template/expected.py new file mode 100644 index 0000000..ae8f84a --- /dev/null +++ b/tests/test_data/map_tests/template/expected.py @@ -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!!", + }, +) diff --git a/tests/test_data/map_tests/template/map.json b/tests/test_data/map_tests/template/map.json new file mode 100644 index 0000000..c0b1b40 --- /dev/null +++ b/tests/test_data/map_tests/template/map.json @@ -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 +} \ No newline at end of file diff --git a/tests/test_data/map_tests/template/template.json b/tests/test_data/map_tests/template/template.json new file mode 100644 index 0000000..fc39229 --- /dev/null +++ b/tests/test_data/map_tests/template/template.json @@ -0,0 +1,12 @@ +{ "object": + { + "height":38.2811778048473, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":63.6585878103079 + }, + "type":"template" +} \ No newline at end of file diff --git a/tests/test_data/map_tests/template/template_tile.json b/tests/test_data/map_tests/template/template_tile.json new file mode 100644 index 0000000..e215e23 --- /dev/null +++ b/tests/test_data/map_tests/template/template_tile.json @@ -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" +} \ No newline at end of file diff --git a/tests/test_data/map_tests/template/tileset.json b/tests/test_data/map_tests/template/tileset.json new file mode 100644 index 0000000..1a07451 --- /dev/null +++ b/tests/test_data/map_tests/template/tileset.json @@ -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" +} \ No newline at end of file diff --git a/tests/test_map.py b/tests/test_map.py index 2d16edb..0019238 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -17,6 +17,7 @@ ALL_MAP_TESTS = [ MAP_TESTS / "no_background_color", MAP_TESTS / "hexagonal", MAP_TESTS / "embedded_tileset", + MAP_TESTS / "template", ] diff --git a/tests/test_tiled_object.py b/tests/test_tiled_object.py index 63dfd0c..f202029 100644 --- a/tests/test_tiled_object.py +++ b/tests/test_tiled_object.py @@ -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)