-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathconftest.py
More file actions
102 lines (72 loc) · 2.78 KB
/
conftest.py
File metadata and controls
102 lines (72 loc) · 2.78 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Test directory configuration."""
from __future__ import annotations
import random
import warnings
from collections.abc import Callable, Iterator
import pytest
import tcod
from tcod import libtcodpy
# ruff: noqa: D103
def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption("--no-window", action="store_true", help="Skip tests which need a rendering context.")
@pytest.fixture
def uses_window(request: pytest.FixtureRequest) -> Iterator[None]:
"""Marks tests which require a rendering context."""
if request.config.getoption("--no-window"):
pytest.skip("This test needs a rendering context.")
yield None
return
@pytest.fixture(scope="session", params=["SDL", "SDL2"])
def session_console(request: pytest.FixtureRequest) -> 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(libtcodpy, "RENDERER_" + request.param)
libtcodpy.console_set_custom_font(FONT_FILE)
with libtcodpy.console_init_root(WIDTH, HEIGHT, TITLE, FULLSCREEN, RENDERER, vsync=False) as con:
yield con
@pytest.fixture
def console(session_console: tcod.console.Console) -> tcod.console.Console:
console = session_console
libtcodpy.console_flush()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
console.default_fg = (255, 255, 255)
console.default_bg = (0, 0, 0)
console.default_bg_blend = libtcodpy.BKGND_SET
console.default_alignment = libtcodpy.LEFT
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() -> libtcodpy.Color:
return libtcodpy.Color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
@pytest.fixture
def bg() -> libtcodpy.Color:
return libtcodpy.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: pytest.FixtureRequest) -> Callable[[], int | str]:
"""Test with multiple types of ascii/latin1 characters."""
return globals()[f"ch_{request.param}"]() # type: ignore[no-any-return]