-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathtest_sdl.py
More file actions
83 lines (69 loc) · 2.82 KB
/
test_sdl.py
File metadata and controls
83 lines (69 loc) · 2.82 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
"""Test SDL specific features."""
import sys
import numpy as np
import pytest
import tcod.sdl.render
import tcod.sdl.sys
import tcod.sdl.video
# ruff: noqa: D103
def test_sdl_window() -> None:
assert tcod.sdl.video.get_grabbed_window() is None
window = tcod.sdl.video.new_window(1, 1)
window.raise_window()
window.maximize()
window.restore()
window.minimize()
window.hide()
window.show()
assert window.title == sys.argv[0]
window.title = "Title"
assert window.title == "Title"
assert window.opacity == 1.0 # noqa: PLR2004
window.position = window.position
window.fullscreen = window.fullscreen
window.resizable = window.resizable
window.size = window.size
window.min_size = window.min_size
window.max_size = window.max_size
window.border_size # noqa: B018
window.set_icon(np.zeros((32, 32, 3), dtype=np.uint8))
with pytest.raises(TypeError):
window.set_icon(np.zeros((32, 32, 5), dtype=np.uint8))
with pytest.raises(TypeError):
window.set_icon(np.zeros((32, 32), dtype=np.uint8))
window.opacity = window.opacity
window.grab = window.grab
def test_sdl_window_bad_types() -> None:
with pytest.raises(TypeError):
tcod.sdl.video.Window(tcod.ffi.cast("SDL_Window*", tcod.ffi.NULL))
with pytest.raises(TypeError):
tcod.sdl.video.Window(tcod.ffi.new("SDL_Rect*"))
def test_sdl_screen_saver() -> None:
tcod.sdl.sys.init()
assert tcod.sdl.video.screen_saver_allowed(False) is False
assert tcod.sdl.video.screen_saver_allowed(True) is True
assert tcod.sdl.video.screen_saver_allowed() is True
def test_sdl_render() -> None:
window = tcod.sdl.video.new_window(1, 1)
render = tcod.sdl.render.new_renderer(window, software=True, vsync=False, target_textures=True)
render.present()
rgb = render.upload_texture(np.zeros((8, 8, 3), np.uint8))
assert (rgb.width, rgb.height) == (8, 8)
assert rgb.access == tcod.sdl.render.TextureAccess.STATIC
assert rgb.format == tcod.lib.SDL_PIXELFORMAT_RGB24
rgb.alpha_mod = rgb.alpha_mod
rgb.blend_mode = rgb.blend_mode
rgb.color_mod = rgb.color_mod
rgba = render.upload_texture(np.zeros((8, 8, 4), np.uint8), access=tcod.sdl.render.TextureAccess.TARGET)
with render.set_render_target(rgba):
render.copy(rgb)
with pytest.raises(TypeError):
render.upload_texture(np.zeros((8, 8, 5), np.uint8))
assert (render.read_pixels() == (0, 0, 0, 255)).all()
assert (render.read_pixels(format="RGB") == (0, 0, 0)).all()
assert render.read_pixels(rect=(1, 2, 3, 4)).shape == (4, 3, 4)
def test_sdl_render_bad_types() -> None:
with pytest.raises(TypeError):
tcod.sdl.render.Renderer(tcod.ffi.cast("SDL_Renderer*", tcod.ffi.NULL))
with pytest.raises(TypeError):
tcod.sdl.render.Renderer(tcod.ffi.new("SDL_Rect*"))