add basic unit tests

Windows can't be hidden yet because texture rendering seems to fail in
this case. This will have to be investigated later.
This commit is contained in:
Lephe 2019-10-06 02:08:58 +02:00
parent 69b5b52fdd
commit 7db38aac06
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 78 additions and 0 deletions

View File

@ -33,6 +33,8 @@ class Window:
# Create the window
mode = SDL_WINDOW_HIDDEN if self.quiet else SDL_WINDOW_SHOWN
# TODO: If the window is hidden, nothing is rendered
mode = SDL_WINDOW_SHOWN
self.w = SDL_CreateWindow("fx-92 Scientifique Collège+".encode(),
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
self.width*self.scale, self.height*self.scale, mode)

72
tests.py Executable file
View File

@ -0,0 +1,72 @@
#! /usr/bin/python3
import sys
import glob
import os.path
import subprocess
from PIL import Image
from PIL import ImageChops
def imgequal(ref, out):
ref = Image.open(ref)
out = Image.open(out)
diff = ImageChops.difference(ref, out)
return diff.getbbox() is None
def runtest(program, refout=None, refimg=None):
st = subprocess.run("./fx92.py --quiet --save=/tmp/fx92-test.bmp".split()
+ [program], stdout=subprocess.PIPE)
if st.returncode != 0:
print(" -> Execution FAILED!")
return 0
print(" Execution completed.")
success = True
if refout is not None:
with open(refout, "r") as fp:
refout = fp.read()
if st.stdout == refout:
print(" Output is correct.")
else:
print(" -> Output is incorrect!")
success = False
if refimg is not None:
if imgequal(refimg, "/tmp/fx92-test.bmp"):
print(" Image is correct.")
else:
print(" -> Image is incorrect!")
success = False
return success
def main():
paths = glob.glob("tests/*.txt")
print("Found {} tests.".format(len(paths)))
total = 0
passed = 0
for t in paths:
print("\n{}:".format(t))
refout = t[:-4] + ".out"
refout = refout if os.path.isfile(refout) else None
refimg = t[:-4] + ".png"
refimg = refimg if os.path.isfile(refimg) else None
passed += runtest(t, refout=refout, refimg=refimg)
total += 1
if passed < total:
print("\nWarning, some tests failed!")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())

BIN
tests/corners.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

4
tests/corners.txt Normal file
View File

@ -0,0 +1,4 @@
goto -90, 23; pendown; goto x-5, y; goto x, y-5; penup
goto -90, -23; pendown; goto x-5, y; goto x, y+5; penup
goto 91, 23; pendown; goto x+5, y; goto x, y-5; penup
goto 91, -23; pendown; goto x+5, y; goto x, y+5; penup