From e31eb0ccf04486c8fc0047907443900f2bbef6cd Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 9 Jan 2014 23:12:32 +0000 Subject: [PATCH] [SCons] Include Python unit tests individually in test result summary --- test/SConscript | 18 ++++++++++++------ test/python/runCythonTests.py | 20 +++++++++++++++++++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/test/SConscript b/test/SConscript index fc7a7ebd1..ebbda8114 100644 --- a/test/SConscript +++ b/test/SConscript @@ -57,8 +57,8 @@ def addTestProgram(subdir, progName): [], [Delete(passedFile.abspath)])) -def addTestScript(testname, subdir, script, interpreter, args='', - dependencies=(), env_vars={}, optional=False): +def addPythonTest(testname, subdir, script, interpreter, outfile, + args='', dependencies=(), env_vars={}, optional=False): """ 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] if not os.path.isdir(workDir): os.mkdir(workDir) + if os.path.exists(outfile): + os.remove(outfile) environ = dict(env['ENV']) for k,v in env_vars.iteritems(): @@ -80,10 +82,13 @@ def addTestScript(testname, subdir, script, interpreter, args='', if not code: # Test was successful 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() passedFile = File(pjoin(subdir, '%s.passed' % testname)) @@ -169,10 +174,11 @@ def make_python_tests(version): # tests (test-cython2) for the main suite. for subset in python_subtests: name = 'cython%i-' %version + subset if subset else 'cython%i' % version - pyTest = addTestScript( + pyTest = addPythonTest( name, 'python', 'runCythonTests.py', args=subset, 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] + localenv['python%i_extension' % version] + mglob(localenv, test_root, 'py')), diff --git a/test/python/runCythonTests.py b/test/python/runCythonTests.py index 7afb52ed7..ed1ad965e 100644 --- a/test/python/runCythonTests.py +++ b/test/python/runCythonTests.py @@ -23,13 +23,31 @@ from cantera.test.utilities import unittest import cantera 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__': print('\n* INFO: using Cantera module found at this location:') print('* ', repr(cantera.__file__), '\n') sys.stdout.flush() loader = unittest.TestLoader() - runner = unittest.TextTestRunner(verbosity=2) + runner = unittest.TextTestRunner(verbosity=2, resultclass=TestResult) suite = unittest.TestSuite() subsets = [] for name in dir(cantera.test):