32 |
import sys |
import sys |
33 |
import traceback |
import traceback |
34 |
sys.path.insert(0, ".") |
sys.path.insert(0, ".") |
|
|
|
35 |
import unittest, os.path, fnmatch, string, imp |
import unittest, os.path, fnmatch, string, imp |
36 |
import java |
import java |
37 |
from gzz.client import GraphicsAPI |
from gzz.client import GraphicsAPI |
38 |
|
import gzz.util.saveimage |
39 |
|
|
40 |
true = 1 |
true = 1 |
41 |
false = 0 |
false = 0 |
42 |
enableJNI = false |
enableJNI = false |
43 |
|
|
44 |
|
|
45 |
|
class Result_SaveImage(unittest._TextTestResult): |
46 |
|
def startTest(self, test): |
47 |
|
from test.tools import gfx |
48 |
|
print "START_RS\n" |
49 |
|
gfx.didRender = 0 |
50 |
|
unittest._TextTestResult.startTest(self, test) |
51 |
|
def addError(self, test, err): |
52 |
|
self.saveFailure(test) |
53 |
|
unittest._TextTestResult.addError(self, test, err) |
54 |
|
|
55 |
|
def addFailure(self, test, err): |
56 |
|
self.saveFailure(test) |
57 |
|
unittest._TextTestResult.addFailure(self, test, err) |
58 |
|
|
59 |
|
def saveFailure(self, test): |
60 |
|
from test.tools import gfx |
61 |
|
print "SAVEFAILURE? ", gfx.didRender |
62 |
|
if not gfx.didRender: |
63 |
|
return |
64 |
|
name = test.id() |
65 |
|
file = "testfail_"+name+".png" |
66 |
|
print "Saving result of graphical test to ", file |
67 |
|
s = gfx.win.getSize() |
68 |
|
gzz.util.saveimage.save(file, |
69 |
|
gfx.win.readPixels(0, 0, s.width, s.height), |
70 |
|
s.width, s.height |
71 |
|
) |
72 |
|
|
73 |
|
class SavingTestRunner(unittest.TextTestRunner): |
74 |
|
def _makeResult(self): |
75 |
|
return Result_SaveImage(self.stream, self.descriptions, self.verbosity) |
76 |
|
|
77 |
|
|
78 |
class NeedGLError: |
class NeedGLError: |
79 |
pass |
pass |
80 |
|
|
195 |
for t in tests(files) if load(t)]) |
for t in tests(files) if load(t)]) |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
# Have to do before importing test.tools.gfx |
200 |
if __name__ == '__main__': |
if __name__ == '__main__': |
201 |
sys.path.insert(0, ".") |
sys.path.insert(0, ".") |
202 |
import getopt |
import getopt |
221 |
class Starter(java.lang.Runnable): |
class Starter(java.lang.Runnable): |
222 |
def run(self): |
def run(self): |
223 |
try: |
try: |
224 |
unittest.TextTestRunner(verbosity=2).run(suite(test)) |
SavingTestRunner(verbosity=2).run(suite(test)) |
225 |
except: |
except: |
226 |
typ, val, tra = sys.exc_info() |
typ, val, tra = sys.exc_info() |
227 |
print (repr((typ, val, tra))) |
print (repr((typ, val))) |
228 |
|
print str(val) |
229 |
l = traceback.format_list(traceback.extract_tb(tra)) |
l = traceback.format_list(traceback.extract_tb(tra)) |
230 |
print "\n".join(l) |
print "\n".join(l) |
231 |
java.lang.System.exit(0) |
java.lang.System.exit(0) |