mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2026-01-06 19:39:34 +01:00
test(tileset): add tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
"""Tests for tilesets"""
|
"""Tests for tilesets"""
|
||||||
|
import importlib.util
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -12,12 +13,24 @@ TEST_DATA = TESTS_DIR / "test_data"
|
|||||||
TILE_SETS = TEST_DATA / "tilesets"
|
TILE_SETS = TEST_DATA / "tilesets"
|
||||||
|
|
||||||
|
|
||||||
ALL_TILESETS = TILE_SETS.glob("*.json")
|
ALL_TILESET_DIRS = TILE_SETS.glob("*")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("raw_tileset", ALL_TILESETS)
|
@pytest.mark.parametrize("tileset_dir", ALL_TILESET_DIRS)
|
||||||
def test_tilesets_integration(raw_tileset):
|
def test_tilesets_integration(tileset_dir):
|
||||||
""" This could be redundant, but it is useful just to ensure that anything in there
|
""" This could be redundant, but it is useful just to ensure that anything in there
|
||||||
is at least sanity checked"""
|
is at least sanity checked"""
|
||||||
tileset_ = tileset.cast(json.loads(raw_tileset))
|
# it's a PITA to import like this, don't do it
|
||||||
assert tileset_ is not None
|
# https://stackoverflow.com/a/67692/1342874
|
||||||
|
spec = importlib.util.spec_from_file_location(
|
||||||
|
"expected", tileset_dir / "expected.py"
|
||||||
|
)
|
||||||
|
expected = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(expected)
|
||||||
|
|
||||||
|
raw_tileset_path = tileset_dir / "tileset.json"
|
||||||
|
|
||||||
|
with open(raw_tileset_path) as raw_tileset:
|
||||||
|
tileset_ = tileset.cast(json.loads(raw_tileset))
|
||||||
|
|
||||||
|
assert tileset_ == expected.EXPECTED
|
||||||
|
|||||||
Reference in New Issue
Block a user