Skip to content

Commit 15d0097

Browse files
committed
Add some tests.
1 parent 418a9ba commit 15d0097

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/TEST_init.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .__init__ import sdl3, TEST_RegisterFunction
2+
3+
@TEST_RegisterFunction
4+
def TEST_SDL_Init():
5+
assert sdl3.SDL_Init(0), "SDL_Init failed."
6+
assert sdl3.SDL_GetError() == "".encode(), "SDL_GetError failed."
7+
sdl3.SDL_Quit()
8+
9+
@TEST_RegisterFunction
10+
def TEST_SDL_CreateWindow():
11+
assert sdl3.SDL_Init(sdl3.SDL_INIT_VIDEO), "SDL_Init failed."
12+
assert (window := sdl3.SDL_CreateWindow("Test".encode(), 1600, 900, sdl3.SDL_WINDOW_RESIZABLE)), "SDL_CreateWindow failed."
13+
assert sdl3.SDL_GetError() == "".encode(), "SDL_GetError failed."
14+
sdl3.SDL_DestroyWindow(window)
15+
sdl3.SDL_Quit()

tests/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os, sys, atexit
2+
3+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
4+
5+
import sdl3
6+
7+
functions = []
8+
9+
def TEST_RegisterFunction(func):
10+
functions.append(func)
11+
12+
from tests.TEST_init import *
13+
14+
@atexit.register
15+
def TEST_RunAllTests():
16+
if not functions: return
17+
successful, failed = 0, 0
18+
19+
for func in functions:
20+
try:
21+
func()
22+
print("\33[32m", f"Test '{func.__name__}' passed.", "\33[0m", sep = "", flush = True)
23+
successful += 1
24+
25+
except AssertionError as error:
26+
print("\33[31m", f"Test '{func.__name__}' failed: {error}", "\33[0m", sep = "", flush = True)
27+
failed += 1
28+
29+
print("\33[35m", f"{successful} tests passed, {failed} tests failed.", "\33[0m", sep = "", flush = True)
30+
assert not failed, "There are some failed tests."

0 commit comments

Comments
 (0)