[SCons] Include Python unit tests individually in test result summary
This commit is contained in:
parent
a75a9c6e21
commit
e31eb0ccf0
2 changed files with 31 additions and 7 deletions
|
|
@ -57,8 +57,8 @@ def addTestProgram(subdir, progName):
|
||||||
[], [Delete(passedFile.abspath)]))
|
[], [Delete(passedFile.abspath)]))
|
||||||
|
|
||||||
|
|
||||||
def addTestScript(testname, subdir, script, interpreter, args='',
|
def addPythonTest(testname, subdir, script, interpreter, outfile,
|
||||||
dependencies=(), env_vars={}, optional=False):
|
args='', dependencies=(), env_vars={}, optional=False):
|
||||||
"""
|
"""
|
||||||
Create targets for running and resetting a test script.
|
Create targets for running and resetting a test script.
|
||||||
"""
|
"""
|
||||||
|
|
@ -69,6 +69,8 @@ def addTestScript(testname, subdir, script, interpreter, args='',
|
||||||
del testResults.tests[passedFile.name]
|
del testResults.tests[passedFile.name]
|
||||||
if not os.path.isdir(workDir):
|
if not os.path.isdir(workDir):
|
||||||
os.mkdir(workDir)
|
os.mkdir(workDir)
|
||||||
|
if os.path.exists(outfile):
|
||||||
|
os.remove(outfile)
|
||||||
|
|
||||||
environ = dict(env['ENV'])
|
environ = dict(env['ENV'])
|
||||||
for k,v in env_vars.iteritems():
|
for k,v in env_vars.iteritems():
|
||||||
|
|
@ -80,10 +82,13 @@ def addTestScript(testname, subdir, script, interpreter, args='',
|
||||||
if not code:
|
if not code:
|
||||||
# Test was successful
|
# Test was successful
|
||||||
open(target[0].path, 'w').write(time.asctime()+'\n')
|
open(target[0].path, 'w').write(time.asctime()+'\n')
|
||||||
testResults.passed[passedFile.name] = True
|
|
||||||
else:
|
|
||||||
testResults.failed[passedFile.name] = True
|
|
||||||
|
|
||||||
|
for line in open(outfile):
|
||||||
|
status, name = line.strip().split(': ', 1)
|
||||||
|
if status == 'PASS':
|
||||||
|
testResults.passed[':'.join((testname,name))] = 1
|
||||||
|
elif status in ('FAIL', 'ERROR'):
|
||||||
|
testResults.failed[':'.join((testname,name))] = 1
|
||||||
|
|
||||||
testenv = localenv.Clone()
|
testenv = localenv.Clone()
|
||||||
passedFile = File(pjoin(subdir, '%s.passed' % testname))
|
passedFile = File(pjoin(subdir, '%s.passed' % testname))
|
||||||
|
|
@ -169,10 +174,11 @@ def make_python_tests(version):
|
||||||
# tests (test-cython2) for the main suite.
|
# tests (test-cython2) for the main suite.
|
||||||
for subset in python_subtests:
|
for subset in python_subtests:
|
||||||
name = 'cython%i-' %version + subset if subset else 'cython%i' % version
|
name = 'cython%i-' %version + subset if subset else 'cython%i' % version
|
||||||
pyTest = addTestScript(
|
pyTest = addPythonTest(
|
||||||
name, 'python', 'runCythonTests.py',
|
name, 'python', 'runCythonTests.py',
|
||||||
args=subset,
|
args=subset,
|
||||||
interpreter='$python_cmd' if version == 2 else '$python3_cmd',
|
interpreter='$python_cmd' if version == 2 else '$python3_cmd',
|
||||||
|
outfile=File('#test/work/python%d-results.txt' % version).abspath,
|
||||||
dependencies=(localenv['python%i_module' % version] +
|
dependencies=(localenv['python%i_module' % version] +
|
||||||
localenv['python%i_extension' % version] +
|
localenv['python%i_extension' % version] +
|
||||||
mglob(localenv, test_root, 'py')),
|
mglob(localenv, test_root, 'py')),
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,31 @@ from cantera.test.utilities import unittest
|
||||||
import cantera
|
import cantera
|
||||||
import cantera.test
|
import cantera.test
|
||||||
|
|
||||||
|
class TestResult(unittest.TextTestResult):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
unittest.TextTestResult.__init__(self, *args, **kwargs)
|
||||||
|
self.outfile = open('python%d-results.txt' % sys.version_info[0], 'w')
|
||||||
|
|
||||||
|
def addSuccess(self, test):
|
||||||
|
self.outfile.write('PASS: %s\n' % test)
|
||||||
|
unittest.TextTestResult.addSuccess(self, test)
|
||||||
|
|
||||||
|
def addFailure(self, test, err):
|
||||||
|
self.outfile.write('FAIL: %s\n' % test)
|
||||||
|
unittest.TextTestResult.addFailure(self, test, err)
|
||||||
|
|
||||||
|
def addFailure(self, test, err):
|
||||||
|
self.outfile.write('ERROR: %s\n' % test)
|
||||||
|
unittest.TextTestResult.addFailure(self, test, err)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print('\n* INFO: using Cantera module found at this location:')
|
print('\n* INFO: using Cantera module found at this location:')
|
||||||
print('* ', repr(cantera.__file__), '\n')
|
print('* ', repr(cantera.__file__), '\n')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
loader = unittest.TestLoader()
|
loader = unittest.TestLoader()
|
||||||
runner = unittest.TextTestRunner(verbosity=2)
|
runner = unittest.TextTestRunner(verbosity=2, resultclass=TestResult)
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
subsets = []
|
subsets = []
|
||||||
for name in dir(cantera.test):
|
for name in dir(cantera.test):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue