85 lines
2.2 KiB
Python
85 lines
2.2 KiB
Python
from io import StringIO
|
|
from textwrap import dedent
|
|
|
|
import pytest
|
|
|
|
from tilemapper import battlemap, tileset
|
|
from tilemapper.grid import X_COORDS
|
|
|
|
|
|
@pytest.fixture
|
|
def manager():
|
|
return tileset.TileSetManager()
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_map():
|
|
return dedent(
|
|
"""
|
|
# ........ 1
|
|
# ........ ........ 2
|
|
# ........ ........
|
|
# .......L...D... D
|
|
# ........ .... ...
|
|
# ........ ...d ...
|
|
# .
|
|
# .........S. 3
|
|
# 5 . .
|
|
# ....S... ...d.... 4
|
|
# ........ ........
|
|
# ........ ........
|
|
|
|
[map]
|
|
name = "sample map"
|
|
description = "sample dungeon"
|
|
|
|
[1]
|
|
name = "room 1"
|
|
description = "A large empty room."
|
|
notes = [
|
|
"Locked door DC 15"
|
|
]
|
|
[2]
|
|
name = "room 2"
|
|
[3]
|
|
name = "room 3"
|
|
[4]
|
|
name = "room 4"
|
|
[5]
|
|
name = "room 5"
|
|
|
|
"""
|
|
)
|
|
|
|
|
|
def test_tileset_loader(manager):
|
|
assert "colorized" in manager.available
|
|
assert "ascii" in manager.available
|
|
|
|
|
|
def test_renderer(manager, sample_map):
|
|
test_map = battlemap.BattleMap(source=StringIO(sample_map), tileset=manager.load("ascii"))
|
|
test_map.load()
|
|
assert test_map.width == 21
|
|
assert test_map.height == 12
|
|
|
|
srclines = sample_map.splitlines()[1:]
|
|
strlines = str(test_map).splitlines()
|
|
for i in range(len(strlines)):
|
|
assert strlines[i] == srclines[i].lstrip(" #").ljust(21, " ")
|
|
|
|
|
|
def test_grid_coordiates(manager):
|
|
coord_length = len(X_COORDS)
|
|
map_size = 2 * coord_length + 1
|
|
bigmap = StringIO((" # " + ("." * map_size) + "\n") * map_size)
|
|
test_map = battlemap.BattleMap(source=bigmap, tileset=manager.load("ascii"))
|
|
test_map.load()
|
|
assert test_map.grid.data[-1][-1].coordinates == (f"{map_size - 1}", X_COORDS[0] * 3)
|
|
|
|
lines = test_map.top_coordinates.splitlines()
|
|
assert len(lines) == 3
|
|
assert lines[0] == (" " * (map_size - 1)) + X_COORDS[0]
|
|
assert lines[1][: (coord_length + 1)] == (" " * coord_length) + X_COORDS[0]
|
|
assert lines[2] == "".join(X_COORDS) + ((coord_length + 1) * X_COORDS[0])
|