Initial tests for worlds

This commit is contained in:
Darren Eberly
2021-05-15 23:50:15 -04:00
parent 6beb77b97d
commit e5caf6daee
17 changed files with 774 additions and 0 deletions

View File

@@ -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],
],
)
],
),
),
],
)

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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],
],
)
],
),
),
],
)

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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"
}

View File

@@ -0,0 +1,12 @@
{
"patterns": [
{
"regexp": "map_p(\\d+)-n(\\d+)\\.json",
"multiplierX": 160,
"multiplierY": 160,
"offsetX": 0,
"offsetY": 0
}
],
"type": "world"
}

View File

@@ -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],
],
)
],
),
),
],
)

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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"
}

View File

@@ -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"
}

35
tests/test_world.py Normal file
View File

@@ -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