From 7db38aac065268a83138634f94e8c73285f295c0 Mon Sep 17 00:00:00 2001 From: Lephe Date: Sun, 6 Oct 2019 02:08:58 +0200 Subject: [PATCH] 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. --- fx92/drawing.py | 2 ++ tests.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++ tests/corners.png | Bin 0 -> 1171 bytes tests/corners.txt | 4 +++ 4 files changed, 78 insertions(+) create mode 100755 tests.py create mode 100644 tests/corners.png create mode 100644 tests/corners.txt diff --git a/fx92/drawing.py b/fx92/drawing.py index 55ef608..e2d79a2 100644 --- a/fx92/drawing.py +++ b/fx92/drawing.py @@ -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) diff --git a/tests.py b/tests.py new file mode 100755 index 0000000..c5ce8aa --- /dev/null +++ b/tests.py @@ -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()) diff --git a/tests/corners.png b/tests/corners.png new file mode 100644 index 0000000000000000000000000000000000000000..8fd17ce19ff2ffb4366473bb3d9637e0f651893e GIT binary patch literal 1171 zcmV;E1Z?|>P)I$000A;dQ@0+Qek%> zaB^>EX>4U6ba`-PAZ2)IW&i+q+SQg@b|fbZhTm%ySpvEtu^etXCp*aU^Hbe!JDxc+ zo=IK;?t-R4g8!2!U;D2=^ZEmYSn8$bQCqDAMVmJ6=tOxh``JFmsObHCEA)KQ_3;OJ zTf`WVGw}H8`W%<%_?w~nYGLR*KahP|ATR&?(XscJWB$jEOp2C|CEh=oD>C=vbX_ZC zsEVJZ`h5tjV0UO$`gm6|yV zG$J};0zEwdGan9gWR&y7G$5dSa(EDtXaRRRIOHP^?GuyySTb}b@%Y*JtQYbmK|S<^GJWq(n7QvIg>0yTP4tO4> z!uU`yI2yOPyaR?Bfa!aCeIEGT_J@W{mqM>mR^_?+OoM>Id#@Hzk={FKX`^#hUY4?R z`pVKPl+~66;?%OE73T|S+&IW-WP8Jz{{{hVSL;uvEw%sv010qNS#tmYE+YT{ zE+YYWr9XB6000McNliru;|c{8IVpFsUs3=70E|gQK~#9!?c6aAz#t3+LCpXEYNVNDq?IhbHJB~s3(e{)6?`7=nxPBLO|R)gDhy=KnMr{As`SC0zyCt2n2+H z5D)?a0U;m+gn&Rm2nYcoAOr*gLO=)z0fB%J5CTF#ARq*UfDjM}h%>wsO`{&~MB^8R lfDjPxj_AUs=4UmRlLg(64_EHDd_w>L002ovPDHLkV1ndc6chje literal 0 HcmV?d00001 diff --git a/tests/corners.txt b/tests/corners.txt new file mode 100644 index 0000000..ddbbc7c --- /dev/null +++ b/tests/corners.txt @@ -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