File: conftest.py

package info (click to toggle)
libtcod 1.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,728 kB
  • sloc: ansic: 46,186; cpp: 13,523; python: 4,814; makefile: 44; sh: 25
file content (123 lines) | stat: -rw-r--r-- 2,905 bytes parent folder | download | duplicates (2)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import random

import pytest

import libtcodpy

FONT_FILE = "../terminal.png"
WIDTH = 12
HEIGHT = 10
TITLE = "libtcodpy tests"
FULLSCREEN = False
RENDERER = libtcodpy.RENDERER_SDL2


@pytest.fixture(scope="module")
def session_console():
    libtcodpy.console_set_custom_font(FONT_FILE)
    assert libtcodpy.console_init_root(WIDTH, HEIGHT, TITLE, FULLSCREEN, RENDERER) == 0
    console = None

    assert libtcodpy.console_get_width(console) == WIDTH
    assert libtcodpy.console_get_height(console) == HEIGHT
    assert libtcodpy.console_is_fullscreen() == FULLSCREEN
    libtcodpy.console_set_window_title(TITLE)
    assert not libtcodpy.console_is_window_closed()

    libtcodpy.sys_get_current_resolution()
    libtcodpy.sys_get_char_size()
    libtcodpy.sys_set_renderer(RENDERER)
    libtcodpy.sys_get_renderer()

    yield console
    libtcodpy.console_delete(console)


@pytest.fixture(scope="function")
def console(session_console):
    """Return a root console.

    Be sure to use this fixture if the GUI needs to be initialized for a test.
    """
    console = session_console
    assert libtcodpy.console_flush() == 0
    libtcodpy.console_set_default_foreground(console, libtcodpy.white)
    libtcodpy.console_set_default_background(console, libtcodpy.black)
    libtcodpy.console_set_background_flag(console, libtcodpy.BKGND_SET)
    libtcodpy.console_set_alignment(console, libtcodpy.LEFT)
    libtcodpy.console_clear(console)
    return console


@pytest.fixture()
def offscreen(console):
    """Return an off-screen console with the same size as the root console."""
    offscreen = libtcodpy.console_new(
        libtcodpy.console_get_width(console),
        libtcodpy.console_get_height(console),
    )
    yield offscreen
    libtcodpy.console_delete(offscreen)


@pytest.fixture()
def fg():
    return libtcodpy.Color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))


@pytest.fixture()
def bg():
    return libtcodpy.Color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))


try:
    unichr
except NameError:
    unichr = chr


def ch_ascii_int():
    return random.randint(0x21, 0x7F)


def ch_ascii_str():
    return chr(ch_ascii_int())


def ch_latin1_int():
    return random.randint(0x80, 0xFF)


def ch_latin1_str():
    return chr(ch_latin1_int())


def ch_bmp_int():
    # Basic Multilingual Plane, before surrogates
    return random.randint(0x100, 0xD7FF)


def ch_bmp_str():
    return unichr(ch_bmp_int())


def ch_smp_int():
    return random.randint(0x10000, 0x1F9FF)


def ch_smp_str():
    return unichr(ch_bmp_int())


@pytest.fixture(
    params=[
        "ascii_int",
        "ascii_str",
        "latin1_int",
        "latin1_str",
        #'bmp_int', 'bmp_str', # causes crashes
    ]
)
def ch(request):
    """Test with multiple types of ascii/latin1 characters"""
    return globals()["ch_%s" % request.param]()