forked from libtcod/python-tcod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
86 lines (61 loc) · 2.38 KB
/
conftest.py
File metadata and controls
86 lines (61 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import random
import warnings
from typing import Any, Callable, Iterator, Union
import pytest
import tcod
def pytest_addoption(parser: Any) -> None:
parser.addoption("--no-window", action="store_true", help="Skip tests which need a rendering context.")
@pytest.fixture(scope="session", params=["SDL", "SDL2"])
def session_console(request: Any) -> Iterator[tcod.console.Console]:
if request.config.getoption("--no-window"):
pytest.skip("This test needs a rendering context.")
FONT_FILE = "libtcod/terminal.png"
WIDTH = 12
HEIGHT = 10
TITLE = "libtcod-cffi tests"
FULLSCREEN = False
RENDERER = getattr(tcod, "RENDERER_" + request.param)
tcod.console_set_custom_font(FONT_FILE)
with tcod.console_init_root(WIDTH, HEIGHT, TITLE, FULLSCREEN, RENDERER, vsync=False) as con:
yield con
@pytest.fixture(scope="function")
def console(session_console: tcod.console.Console) -> tcod.console.Console:
console = session_console
tcod.console_flush()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
console.default_fg = (255, 255, 255) # type: ignore
console.default_bg = (0, 0, 0) # type: ignore
console.default_bg_blend = tcod.BKGND_SET # type: ignore
console.default_alignment = tcod.LEFT # type: ignore
console.clear()
return console
@pytest.fixture()
def offscreen(console: tcod.console.Console) -> tcod.console.Console:
"""Return an off-screen console with the same size as the root console."""
return tcod.console.Console(console.width, console.height)
@pytest.fixture()
def fg() -> tcod.Color:
return tcod.Color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
@pytest.fixture()
def bg() -> tcod.Color:
return tcod.Color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
def ch_ascii_int() -> int:
return random.randint(0x21, 0x7F)
def ch_ascii_str() -> str:
return chr(ch_ascii_int())
def ch_latin1_int() -> int:
return random.randint(0x80, 0xFF)
def ch_latin1_str() -> str:
return chr(ch_latin1_int())
@pytest.fixture(
params=[
"ascii_int",
"ascii_str",
"latin1_int",
"latin1_str",
]
)
def ch(request: Any) -> Callable[[], Union[int, str]]:
"""Test with multiple types of ascii/latin1 characters"""
return globals()["ch_%s" % request.param]() # type: ignore