-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathtest_sdl.py
More file actions
118 lines (98 loc) · 4.16 KB
/
Copy pathtest_sdl.py
File metadata and controls
118 lines (98 loc) · 4.16 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""Test SDL specific features."""
import sys
import numpy as np
import pytest
import tcod.sdl.render
import tcod.sdl.sys
import tcod.sdl.video
def test_sdl_window(uses_window: None) -> None: # noqa: ARG001
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
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
window.start_text_input(capitalization=tcod.sdl.video.Capitalization.NONE, multiline=False)
window.set_text_input_area((0, 0, 8, 8), 0)
window.stop_text_input()
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(uses_window: None) -> None: # noqa: ARG001
tcod.sdl.sys.init(tcod.sdl.sys.Subsystem.VIDEO)
assert tcod.sdl.video.screen_saver_allowed(False) is False # noqa: FBT003
assert tcod.sdl.video.screen_saver_allowed(True) is True # noqa: FBT003
assert tcod.sdl.video.screen_saver_allowed() is True
def test_sdl_render(uses_window: None) -> None: # noqa: ARG001
window = tcod.sdl.video.new_window(4, 4)
render = tcod.sdl.render.new_renderer(window, driver="software", vsync=False)
render.clear()
render.present()
render.clear()
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
rgb.scale_mode = rgb.scale_mode
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(rect=(0, 0, 3, 4)).shape == (4, 3, 4)
assert (render.read_pixels(format="RGB") == (0, 0, 0)).all()
assert (render.read_pixels() == (0, 0, 0, 255)).all()
render.draw_point((0, 0))
render.draw_line((0, 0), (1, 1))
render.draw_rect((0, 0, 1, 1))
render.fill_rect((0, 0, 1, 1))
render.draw_points([(0, 0)])
render.draw_lines([(0, 0), (1, 1)])
render.draw_rects([(0, 0, 1, 1)])
render.fill_rects([(0, 0, 1, 1)])
for dtype in (np.intc, np.int8, np.uint8, np.float32, np.float16):
render.draw_points(np.ones((3, 2), dtype=dtype))
render.draw_lines(np.ones((3, 2), dtype=dtype))
render.draw_rects(np.ones((3, 4), dtype=dtype))
render.fill_rects(np.ones((3, 4), dtype=dtype))
with pytest.raises(TypeError, match=r"shape\[1\] must be 2"):
render.draw_points(np.ones((3, 1), dtype=dtype))
with pytest.raises(TypeError, match=r"must have 2 axes"):
render.draw_points(np.ones((3,), dtype=dtype))
render.geometry(
None,
np.zeros((1, 2), np.float32),
np.zeros((1, 4), np.float32),
np.zeros((1, 2), np.float32),
np.zeros((3,), np.uint8),
)
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*"))