From e5caf6daee5d8bfb648594674d7876bd90726a4e Mon Sep 17 00:00:00 2001 From: Darren Eberly Date: Sat, 15 May 2021 23:50:15 -0400 Subject: [PATCH] Initial tests for worlds --- tests/test_data/world_tests/both/expected.py | 177 ++++++++++++++++++ .../world_tests/both/map_manual_one.json | 32 ++++ .../test_data/world_tests/both/map_p0-n0.json | 32 ++++ .../test_data/world_tests/both/map_p0-n1.json | 32 ++++ tests/test_data/world_tests/both/tileset.json | 14 ++ tests/test_data/world_tests/both/world.world | 22 +++ .../world_tests/pattern_matched/expected.py | 121 ++++++++++++ .../pattern_matched/map_p0-n0.json | 32 ++++ .../pattern_matched/map_p0-n1.json | 32 ++++ .../world_tests/pattern_matched/tileset.json | 14 ++ .../world_tests/pattern_matched/world.world | 12 ++ .../world_tests/static_defined/expected.py | 121 ++++++++++++ .../world_tests/static_defined/map_01.json | 32 ++++ .../world_tests/static_defined/map_02.json | 32 ++++ .../world_tests/static_defined/tileset.json | 14 ++ .../world_tests/static_defined/world.world | 20 ++ tests/test_world.py | 35 ++++ 17 files changed, 774 insertions(+) create mode 100644 tests/test_data/world_tests/both/expected.py create mode 100644 tests/test_data/world_tests/both/map_manual_one.json create mode 100644 tests/test_data/world_tests/both/map_p0-n0.json create mode 100644 tests/test_data/world_tests/both/map_p0-n1.json create mode 100644 tests/test_data/world_tests/both/tileset.json create mode 100644 tests/test_data/world_tests/both/world.world create mode 100644 tests/test_data/world_tests/pattern_matched/expected.py create mode 100644 tests/test_data/world_tests/pattern_matched/map_p0-n0.json create mode 100644 tests/test_data/world_tests/pattern_matched/map_p0-n1.json create mode 100644 tests/test_data/world_tests/pattern_matched/tileset.json create mode 100644 tests/test_data/world_tests/pattern_matched/world.world create mode 100644 tests/test_data/world_tests/static_defined/expected.py create mode 100644 tests/test_data/world_tests/static_defined/map_01.json create mode 100644 tests/test_data/world_tests/static_defined/map_02.json create mode 100644 tests/test_data/world_tests/static_defined/tileset.json create mode 100644 tests/test_data/world_tests/static_defined/world.world create mode 100644 tests/test_world.py diff --git a/tests/test_data/world_tests/both/expected.py b/tests/test_data/world_tests/both/expected.py new file mode 100644 index 0000000..2fcf738 --- /dev/null +++ b/tests/test_data/world_tests/both/expected.py @@ -0,0 +1,177 @@ +from pathlib import Path + +from pytiled_parser import common_types, layer, tiled_map, tileset, world + +EXPECTED = world.World( + only_show_adjacent=False, + maps=[ + world.WorldMap( + size=common_types.Size(160, 160), + coordinates=common_types.OrderedPair(-160, 0), + tiled_map=tiled_map.TiledMap( + map_file=Path(Path(__file__).parent / "map_manual_one.json") + .absolute() + .resolve(), + infinite=False, + map_size=common_types.Size(5, 5), + next_layer_id=2, + next_object_id=1, + orientation="orthogonal", + render_order="right-down", + tiled_version="1.6.0", + tile_size=common_types.Size(32, 32), + version="1.6", + 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="tileset", + tile_count=48, + tiled_version="1.6.0", + tile_height=32, + tile_width=32, + version="1.6", + type="tileset", + ) + }, + layers=[ + layer.TileLayer( + name="Tile Layer 1", + opacity=1, + visible=True, + id=1, + size=common_types.Size(5, 5), + data=[ + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + ], + ) + ], + ), + ), + world.WorldMap( + size=common_types.Size(160, 160), + coordinates=common_types.OrderedPair(0, 0), + tiled_map=tiled_map.TiledMap( + map_file=Path(Path(__file__).parent / "map_p0-n0.json") + .absolute() + .resolve(), + infinite=False, + map_size=common_types.Size(5, 5), + next_layer_id=2, + next_object_id=1, + orientation="orthogonal", + render_order="right-down", + tiled_version="1.6.0", + tile_size=common_types.Size(32, 32), + version="1.6", + 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="tileset", + tile_count=48, + tiled_version="1.6.0", + tile_height=32, + tile_width=32, + version="1.6", + type="tileset", + ) + }, + layers=[ + layer.TileLayer( + name="Tile Layer 1", + opacity=1, + visible=True, + id=1, + size=common_types.Size(5, 5), + data=[ + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + ], + ) + ], + ), + ), + world.WorldMap( + size=common_types.Size(160, 160), + coordinates=common_types.OrderedPair(0, 160), + tiled_map=tiled_map.TiledMap( + map_file=Path(Path(__file__).parent / "map_p0-n1.json") + .absolute() + .resolve(), + infinite=False, + map_size=common_types.Size(5, 5), + next_layer_id=2, + next_object_id=1, + orientation="orthogonal", + render_order="right-down", + tiled_version="1.6.0", + tile_size=common_types.Size(32, 32), + version="1.6", + 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="tileset", + tile_count=48, + tiled_version="1.6.0", + tile_height=32, + tile_width=32, + version="1.6", + type="tileset", + ) + }, + layers=[ + layer.TileLayer( + name="Tile Layer 1", + opacity=1, + visible=True, + id=1, + size=common_types.Size(5, 5), + data=[ + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + ], + ) + ], + ), + ), + ], +) diff --git a/tests/test_data/world_tests/both/map_manual_one.json b/tests/test_data/world_tests/both/map_manual_one.json new file mode 100644 index 0000000..db2e54a --- /dev/null +++ b/tests/test_data/world_tests/both/map_manual_one.json @@ -0,0 +1,32 @@ +{ "compressionlevel":-1, + "height":5, + "infinite":false, + "layers":[ + { + "data":[30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], + "height":5, + "id":1, + "name":"Tile Layer 1", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":5, + "x":0, + "y":0 + }], + "nextlayerid":2, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.6.0", + "tileheight":32, + "tilesets":[ + { + "firstgid":1, + "source":"tileset.json" + }], + "tilewidth":32, + "type":"map", + "version":"1.6", + "width":5 +} \ No newline at end of file diff --git a/tests/test_data/world_tests/both/map_p0-n0.json b/tests/test_data/world_tests/both/map_p0-n0.json new file mode 100644 index 0000000..db2e54a --- /dev/null +++ b/tests/test_data/world_tests/both/map_p0-n0.json @@ -0,0 +1,32 @@ +{ "compressionlevel":-1, + "height":5, + "infinite":false, + "layers":[ + { + "data":[30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], + "height":5, + "id":1, + "name":"Tile Layer 1", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":5, + "x":0, + "y":0 + }], + "nextlayerid":2, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.6.0", + "tileheight":32, + "tilesets":[ + { + "firstgid":1, + "source":"tileset.json" + }], + "tilewidth":32, + "type":"map", + "version":"1.6", + "width":5 +} \ No newline at end of file diff --git a/tests/test_data/world_tests/both/map_p0-n1.json b/tests/test_data/world_tests/both/map_p0-n1.json new file mode 100644 index 0000000..db2e54a --- /dev/null +++ b/tests/test_data/world_tests/both/map_p0-n1.json @@ -0,0 +1,32 @@ +{ "compressionlevel":-1, + "height":5, + "infinite":false, + "layers":[ + { + "data":[30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], + "height":5, + "id":1, + "name":"Tile Layer 1", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":5, + "x":0, + "y":0 + }], + "nextlayerid":2, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.6.0", + "tileheight":32, + "tilesets":[ + { + "firstgid":1, + "source":"tileset.json" + }], + "tilewidth":32, + "type":"map", + "version":"1.6", + "width":5 +} \ No newline at end of file diff --git a/tests/test_data/world_tests/both/tileset.json b/tests/test_data/world_tests/both/tileset.json new file mode 100644 index 0000000..6f07285 --- /dev/null +++ b/tests/test_data/world_tests/both/tileset.json @@ -0,0 +1,14 @@ +{ "columns":8, + "image":"..\/..\/images\/tmw_desert_spacing.png", + "imageheight":199, + "imagewidth":265, + "margin":1, + "name":"tileset", + "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_data/world_tests/both/world.world b/tests/test_data/world_tests/both/world.world new file mode 100644 index 0000000..8316438 --- /dev/null +++ b/tests/test_data/world_tests/both/world.world @@ -0,0 +1,22 @@ +{ + "maps": [ + { + "fileName": "map_manual_one.json", + "height": 160, + "width": 160, + "x": -160, + "y": 0 + } + ], + "patterns": [ + { + "regexp": "map_p(\\d+)-n(\\d+)\\.json", + "multiplierX": 160, + "multiplierY": 160, + "offsetX": 0, + "offsetY": 0 + } + ], + "onlyShowAdjacentMaps": false, + "type": "world" +} \ No newline at end of file diff --git a/tests/test_data/world_tests/pattern_matched/expected.py b/tests/test_data/world_tests/pattern_matched/expected.py new file mode 100644 index 0000000..b6ab9f0 --- /dev/null +++ b/tests/test_data/world_tests/pattern_matched/expected.py @@ -0,0 +1,121 @@ +from pathlib import Path + +from pytiled_parser import common_types, layer, tiled_map, tileset, world + +EXPECTED = world.World( + only_show_adjacent=False, + maps=[ + world.WorldMap( + size=common_types.Size(160, 160), + coordinates=common_types.OrderedPair(0, 0), + tiled_map=tiled_map.TiledMap( + map_file=Path(Path(__file__).parent / "map_p0-n0.json") + .absolute() + .resolve(), + infinite=False, + map_size=common_types.Size(5, 5), + next_layer_id=2, + next_object_id=1, + orientation="orthogonal", + render_order="right-down", + tiled_version="1.6.0", + tile_size=common_types.Size(32, 32), + version="1.6", + 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="tileset", + tile_count=48, + tiled_version="1.6.0", + tile_height=32, + tile_width=32, + version="1.6", + type="tileset", + ) + }, + layers=[ + layer.TileLayer( + name="Tile Layer 1", + opacity=1, + visible=True, + id=1, + size=common_types.Size(5, 5), + data=[ + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + ], + ) + ], + ), + ), + world.WorldMap( + size=common_types.Size(160, 160), + coordinates=common_types.OrderedPair(0, 160), + tiled_map=tiled_map.TiledMap( + map_file=Path(Path(__file__).parent / "map_p0-n1.json") + .absolute() + .resolve(), + infinite=False, + map_size=common_types.Size(5, 5), + next_layer_id=2, + next_object_id=1, + orientation="orthogonal", + render_order="right-down", + tiled_version="1.6.0", + tile_size=common_types.Size(32, 32), + version="1.6", + 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="tileset", + tile_count=48, + tiled_version="1.6.0", + tile_height=32, + tile_width=32, + version="1.6", + type="tileset", + ) + }, + layers=[ + layer.TileLayer( + name="Tile Layer 1", + opacity=1, + visible=True, + id=1, + size=common_types.Size(5, 5), + data=[ + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + ], + ) + ], + ), + ), + ], +) diff --git a/tests/test_data/world_tests/pattern_matched/map_p0-n0.json b/tests/test_data/world_tests/pattern_matched/map_p0-n0.json new file mode 100644 index 0000000..db2e54a --- /dev/null +++ b/tests/test_data/world_tests/pattern_matched/map_p0-n0.json @@ -0,0 +1,32 @@ +{ "compressionlevel":-1, + "height":5, + "infinite":false, + "layers":[ + { + "data":[30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], + "height":5, + "id":1, + "name":"Tile Layer 1", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":5, + "x":0, + "y":0 + }], + "nextlayerid":2, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.6.0", + "tileheight":32, + "tilesets":[ + { + "firstgid":1, + "source":"tileset.json" + }], + "tilewidth":32, + "type":"map", + "version":"1.6", + "width":5 +} \ No newline at end of file diff --git a/tests/test_data/world_tests/pattern_matched/map_p0-n1.json b/tests/test_data/world_tests/pattern_matched/map_p0-n1.json new file mode 100644 index 0000000..db2e54a --- /dev/null +++ b/tests/test_data/world_tests/pattern_matched/map_p0-n1.json @@ -0,0 +1,32 @@ +{ "compressionlevel":-1, + "height":5, + "infinite":false, + "layers":[ + { + "data":[30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], + "height":5, + "id":1, + "name":"Tile Layer 1", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":5, + "x":0, + "y":0 + }], + "nextlayerid":2, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.6.0", + "tileheight":32, + "tilesets":[ + { + "firstgid":1, + "source":"tileset.json" + }], + "tilewidth":32, + "type":"map", + "version":"1.6", + "width":5 +} \ No newline at end of file diff --git a/tests/test_data/world_tests/pattern_matched/tileset.json b/tests/test_data/world_tests/pattern_matched/tileset.json new file mode 100644 index 0000000..6f07285 --- /dev/null +++ b/tests/test_data/world_tests/pattern_matched/tileset.json @@ -0,0 +1,14 @@ +{ "columns":8, + "image":"..\/..\/images\/tmw_desert_spacing.png", + "imageheight":199, + "imagewidth":265, + "margin":1, + "name":"tileset", + "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_data/world_tests/pattern_matched/world.world b/tests/test_data/world_tests/pattern_matched/world.world new file mode 100644 index 0000000..6ad0898 --- /dev/null +++ b/tests/test_data/world_tests/pattern_matched/world.world @@ -0,0 +1,12 @@ +{ + "patterns": [ + { + "regexp": "map_p(\\d+)-n(\\d+)\\.json", + "multiplierX": 160, + "multiplierY": 160, + "offsetX": 0, + "offsetY": 0 + } + ], + "type": "world" +} \ No newline at end of file diff --git a/tests/test_data/world_tests/static_defined/expected.py b/tests/test_data/world_tests/static_defined/expected.py new file mode 100644 index 0000000..b748577 --- /dev/null +++ b/tests/test_data/world_tests/static_defined/expected.py @@ -0,0 +1,121 @@ +from pathlib import Path + +from pytiled_parser import common_types, layer, tiled_map, tileset, world + +EXPECTED = world.World( + only_show_adjacent=False, + maps=[ + world.WorldMap( + size=common_types.Size(160, 160), + coordinates=common_types.OrderedPair(0, 0), + tiled_map=tiled_map.TiledMap( + map_file=Path(Path(__file__).parent / "map_01.json") + .absolute() + .resolve(), + infinite=False, + map_size=common_types.Size(5, 5), + next_layer_id=2, + next_object_id=1, + orientation="orthogonal", + render_order="right-down", + tiled_version="1.6.0", + tile_size=common_types.Size(32, 32), + version="1.6", + 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="tileset", + tile_count=48, + tiled_version="1.6.0", + tile_height=32, + tile_width=32, + version="1.6", + type="tileset", + ) + }, + layers=[ + layer.TileLayer( + name="Tile Layer 1", + opacity=1, + visible=True, + id=1, + size=common_types.Size(5, 5), + data=[ + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + ], + ) + ], + ), + ), + world.WorldMap( + size=common_types.Size(160, 160), + coordinates=common_types.OrderedPair(160, 0), + tiled_map=tiled_map.TiledMap( + map_file=Path(Path(__file__).parent / "map_02.json") + .absolute() + .resolve(), + infinite=False, + map_size=common_types.Size(5, 5), + next_layer_id=2, + next_object_id=1, + orientation="orthogonal", + render_order="right-down", + tiled_version="1.6.0", + tile_size=common_types.Size(32, 32), + version="1.6", + 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="tileset", + tile_count=48, + tiled_version="1.6.0", + tile_height=32, + tile_width=32, + version="1.6", + type="tileset", + ) + }, + layers=[ + layer.TileLayer( + name="Tile Layer 1", + opacity=1, + visible=True, + id=1, + size=common_types.Size(5, 5), + data=[ + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + [30, 30, 30, 30, 30], + ], + ) + ], + ), + ), + ], +) diff --git a/tests/test_data/world_tests/static_defined/map_01.json b/tests/test_data/world_tests/static_defined/map_01.json new file mode 100644 index 0000000..db2e54a --- /dev/null +++ b/tests/test_data/world_tests/static_defined/map_01.json @@ -0,0 +1,32 @@ +{ "compressionlevel":-1, + "height":5, + "infinite":false, + "layers":[ + { + "data":[30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], + "height":5, + "id":1, + "name":"Tile Layer 1", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":5, + "x":0, + "y":0 + }], + "nextlayerid":2, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.6.0", + "tileheight":32, + "tilesets":[ + { + "firstgid":1, + "source":"tileset.json" + }], + "tilewidth":32, + "type":"map", + "version":"1.6", + "width":5 +} \ No newline at end of file diff --git a/tests/test_data/world_tests/static_defined/map_02.json b/tests/test_data/world_tests/static_defined/map_02.json new file mode 100644 index 0000000..db2e54a --- /dev/null +++ b/tests/test_data/world_tests/static_defined/map_02.json @@ -0,0 +1,32 @@ +{ "compressionlevel":-1, + "height":5, + "infinite":false, + "layers":[ + { + "data":[30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], + "height":5, + "id":1, + "name":"Tile Layer 1", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":5, + "x":0, + "y":0 + }], + "nextlayerid":2, + "nextobjectid":1, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.6.0", + "tileheight":32, + "tilesets":[ + { + "firstgid":1, + "source":"tileset.json" + }], + "tilewidth":32, + "type":"map", + "version":"1.6", + "width":5 +} \ No newline at end of file diff --git a/tests/test_data/world_tests/static_defined/tileset.json b/tests/test_data/world_tests/static_defined/tileset.json new file mode 100644 index 0000000..6f07285 --- /dev/null +++ b/tests/test_data/world_tests/static_defined/tileset.json @@ -0,0 +1,14 @@ +{ "columns":8, + "image":"..\/..\/images\/tmw_desert_spacing.png", + "imageheight":199, + "imagewidth":265, + "margin":1, + "name":"tileset", + "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_data/world_tests/static_defined/world.world b/tests/test_data/world_tests/static_defined/world.world new file mode 100644 index 0000000..5cf3e56 --- /dev/null +++ b/tests/test_data/world_tests/static_defined/world.world @@ -0,0 +1,20 @@ +{ + "maps": [ + { + "fileName": "map_01.json", + "height": 160, + "width": 160, + "x": 0, + "y": 0 + }, + { + "fileName": "map_02.json", + "height": 160, + "width": 160, + "x": 160, + "y": 0 + } + ], + "onlyShowAdjacentMaps": false, + "type": "world" +} diff --git a/tests/test_world.py b/tests/test_world.py new file mode 100644 index 0000000..09024e5 --- /dev/null +++ b/tests/test_world.py @@ -0,0 +1,35 @@ +"""Tests for worlds""" +import importlib.util +import os +from pathlib import Path + +import pytest + +from pytiled_parser import world + +TESTS_DIR = Path(os.path.dirname(os.path.abspath(__file__))) +TEST_DATA = TESTS_DIR / "test_data" +WORLD_TESTS = TEST_DATA / "world_tests" + +ALL_WORLD_TESTS = [ + WORLD_TESTS / "static_defined", + WORLD_TESTS / "pattern_matched", + WORLD_TESTS / "both", +] + + +@pytest.mark.parametrize("world_test", ALL_WORLD_TESTS) +def test_world_integration(world_test): + # it's a PITA to import like this, don't do it + # https://stackoverflow.com/a/67692/1342874 + spec = importlib.util.spec_from_file_location( + "expected", world_test / "expected.py" + ) + expected = importlib.util.module_from_spec(spec) + spec.loader.exec_module(expected) + + raw_world_path = world_test / "world.world" + + casted_world = world.parse_world(raw_world_path) + + assert casted_world == expected.EXPECTED