Skip to content

Commit

Permalink
Add some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aermoss committed Jan 28, 2025
1 parent 418a9ba commit 15d0097
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/TEST_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .__init__ import sdl3, TEST_RegisterFunction

@TEST_RegisterFunction
def TEST_SDL_Init():
assert sdl3.SDL_Init(0), "SDL_Init failed."
assert sdl3.SDL_GetError() == "".encode(), "SDL_GetError failed."
sdl3.SDL_Quit()

@TEST_RegisterFunction
def TEST_SDL_CreateWindow():
assert sdl3.SDL_Init(sdl3.SDL_INIT_VIDEO), "SDL_Init failed."
assert (window := sdl3.SDL_CreateWindow("Test".encode(), 1600, 900, sdl3.SDL_WINDOW_RESIZABLE)), "SDL_CreateWindow failed."
assert sdl3.SDL_GetError() == "".encode(), "SDL_GetError failed."
sdl3.SDL_DestroyWindow(window)
sdl3.SDL_Quit()
30 changes: 30 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os, sys, atexit

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

import sdl3

functions = []

def TEST_RegisterFunction(func):
functions.append(func)

from tests.TEST_init import *

@atexit.register
def TEST_RunAllTests():
if not functions: return
successful, failed = 0, 0

for func in functions:
try:
func()
print("\33[32m", f"Test '{func.__name__}' passed.", "\33[0m", sep = "", flush = True)
successful += 1

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

print("\33[35m", f"{successful} tests passed, {failed} tests failed.", "\33[0m", sep = "", flush = True)
assert not failed, "There are some failed tests."

0 comments on commit 15d0097

Please # to comment.