Files
pytiled_parser/tests/test_map.py
Darren Eberly 674b4b50c4 Changes to API
Should make integration with game engines easier in general.

Puts the burden of color parsing on Pytiled. As well as formatting layer data into a two dimensional list from a straight one dimensional.
2021-02-21 00:58:30 -05:00

36 lines
980 B
Python

"""Tests for maps"""
import importlib.util
import os
from pathlib import Path
import pytest
from pytiled_parser import tiled_map
TESTS_DIR = Path(os.path.dirname(os.path.abspath(__file__)))
TEST_DATA = TESTS_DIR / "test_data"
MAP_TESTS = TEST_DATA / "map_tests"
ALL_MAP_TESTS = [
MAP_TESTS / "no_layers",
MAP_TESTS / "no_background_color",
MAP_TESTS / "hexagonal",
MAP_TESTS / "embedded_tileset",
]
@pytest.mark.parametrize("map_test", ALL_MAP_TESTS)
def test_map_integration(map_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", map_test / "expected.py")
expected = importlib.util.module_from_spec(spec)
spec.loader.exec_module(expected)
raw_maps_path = map_test / "map.json"
casted_map = tiled_map.parse_map(raw_maps_path)
expected.EXPECTED.map_file = casted_map.map_file
assert casted_map == expected.EXPECTED