Files
pytiled_parser/tests/test_layer.py
Benjamin Kirkbride 456fbb1e9c tests(layer): stub
2020-07-27 19:33:46 -04:00

38 lines
1000 B
Python

"""Tests for tilesets"""
import importlib.util
import json
import os
from pathlib import Path
import pytest
from pytiled_parser import layer
TESTS_DIR = Path(os.path.dirname(os.path.abspath(__file__)))
TEST_DATA = TESTS_DIR / "test_data"
LAYER_TESTS = TEST_DATA / "layer_tests"
ALL_LAYER_TESTS = [
LAYER_TESTS / "all_layer_types",
]
@pytest.mark.parametrize("layer_test", ALL_LAYER_TESTS)
def test_layer_integration(layer_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", layer_test / "expected.py"
)
expected = importlib.util.module_from_spec(spec)
spec.loader.exec_module(expected)
raw_layers_path = layer_test / "map.json"
with open(raw_layers_path) as raw_layers_file:
raw_layers = json.load(raw_layers_file)["layers"]
layers = [layer.cast(raw_layer) for raw_layer in raw_layers]
assert layers == expected.EXPECTED