Skip to content

Commit 6527830

Browse files
committed
Update tests.
1 parent 8acfce8 commit 6527830

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

tests/TEST_init.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
from .__init__ import sdl3, TEST_RegisterFunction
1+
from .__init__ import sdl3, TEST_RegisterFunction, TEST_PassFunction
22

3-
@TEST_RegisterFunction
3+
@TEST_RegisterFunction(["Linux", "Darwin", "Windows"])
44
def TEST_SDL_Init():
55
assert sdl3.SDL_Init(0), sdl3.SDL_GetError().decode()
66
assert (error := sdl3.SDL_GetError()) == "".encode(), error.decode()
77
sdl3.SDL_Quit()
88

9-
@TEST_RegisterFunction
9+
@TEST_RegisterFunction(["Darwin", "Windows"])
1010
def TEST_SDL_CreateWindow():
11-
if sdl3.SDL_SYSTEM in ["Linux"]: return
1211
assert sdl3.SDL_Init(sdl3.SDL_INIT_VIDEO), sdl3.SDL_GetError().decode()
1312
assert (window := sdl3.SDL_CreateWindow("Test".encode(), 1600, 900, sdl3.SDL_WINDOW_RESIZABLE)), sdl3.SDL_GetError().decode()
1413
assert (error := sdl3.SDL_GetError()) == "".encode(), error.decode()

tests/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,34 @@
44

55
import sdl3
66

7-
functions = []
7+
functions = {}
88

9-
def TEST_RegisterFunction(func):
10-
functions.append(func)
9+
def TEST_RegisterFunction(systems):
10+
return lambda func: functions.update({func: systems})
11+
12+
class TEST_PassFunction(Exception):
13+
...
1114

1215
from tests.TEST_init import *
1316

1417
@atexit.register
1518
def TEST_RunAllTests():
1619
if not functions: return
17-
successful, failed = 0, 0
20+
passed, failed = 0, 0
1821

19-
for func in functions:
22+
for func, systems in functions.items():
2023
try:
21-
func()
24+
if sdl3.SDL_SYSTEM in systems: func()
25+
else: raise TEST_PassFunction()
2226
print("\33[32m", f"Test '{func.__name__}' passed.", "\33[0m", sep = "", flush = True)
23-
successful += 1
27+
passed += 1
28+
29+
except TEST_PassFunction as error:
30+
print("\33[33m", f"Test '{func.__name__}' is not supported on {sdl3.SDL_SYSTEM}.", "\33[0m", sep = "", flush = True)
2431

2532
except AssertionError as error:
2633
print("\33[31m", f"Test '{func.__name__}' failed: {error}", "\33[0m", sep = "", flush = True)
2734
failed += 1
2835

29-
print("\33[35m", f"{successful} test(s) passed, {failed} test(s) failed.", "\33[0m", sep = "", flush = True)
36+
print("\33[35m", f"{passed} test(s) passed, {failed} test(s) failed.", "\33[0m", sep = "", flush = True)
3037
if failed: os._exit(-1)

0 commit comments

Comments
 (0)