Rename print_report and test_results to snake case

This commit is contained in:
Bryan Weber
2021-04-11 22:27:52 -04:00
committed by Ray Speth
parent febd00c6fe
commit 83eacc021d
4 changed files with 46 additions and 43 deletions

View File

@@ -1929,7 +1929,7 @@ if 'msi' in COMMAND_LINE_TARGETS:
### Tests ###
if any(target.startswith('test') for target in COMMAND_LINE_TARGETS):
env['testNames'] = []
env['test_results'] = env.Command('test_results', [], testResults.printReport)
env['test_results'] = env.Command('test_results', [], test_results.print_report)
if env['python_package'] == 'none':
# copy scripts from the full Cython module

View File

@@ -96,38 +96,41 @@ class TestResults:
that are defined and which ones have passed / failed in order to
print a summary at the end of the build process.
"""
def __init__(self):
self.tests = {}
self.passed = {}
self.failed = {}
def printReport(self, target, source, env):
def print_report(self, target, source, env):
values = {
"passed": sum(self.passed.values()),
"failed": sum(self.failed.values()),
"skipped": len(self.tests),
}
message = textwrap.dedent("""\
*****************************
*** Testing Summary ***
*****************************
Tests passed: {passed!s}
Up-to-date tests skipped: {skipped!s}
Tests failed: {failed!s}
"""
).format_map(values)
if self.failed:
failures = ('Failed tests:' +
''.join('\n - ' + n for n in self.failed) +
'\n')
message = (message + "Failed tests:" +
"".join("\n - " + n for n in self.failed) +
"\n")
message = message + "*****************************"
if self.failed:
output_logger.error("One or more tests failed.\n" + message)
sys.exit(1)
else:
failures = ''
print("""
*****************************
*** Testing Summary ***
*****************************
Tests passed: %(passed)s
Up-to-date tests skipped: %(skipped)s
Tests failed: %(failed)s
%(failures)s
*****************************""" % dict(
passed=sum(self.passed.values()),
failed=sum(self.failed.values()),
skipped=len(self.tests),
failures=failures))
if self.failed:
raise SCons.Errors.BuildError(self, 'One or more tests failed.')
output_logger.info(message)
testResults = TestResults()
test_results = TestResults()
def regression_test(target, source, env):

View File

@@ -48,7 +48,7 @@ def addTestProgram(subdir, progName, env_vars={}):
"""SCons Action to run a compiled gtest program"""
program = source[0]
passedFile = target[0]
testResults.tests.pop(passedFile.name, None)
test_results.tests.pop(passedFile.name, None)
workDir = Dir('#test/work').abspath
resultsFile = pjoin(workDir, 'gtest-%s.xml' % progName)
if os.path.exists(resultsFile):
@@ -78,14 +78,14 @@ def addTestProgram(subdir, progName, env_vars={}):
testName = '{0}: {1}.{2}'.format(progName, test.get('classname'),
test.get('name'))
if test.findall('failure'):
testResults.failed[testName] = 1
test_results.failed[testName] = 1
else:
testResults.passed[testName] = 1
test_results.passed[testName] = 1
else:
# Total failure of the test program - unable to determine status of
# individual tests. This is potentially very bad, so it counts as
# more than one failure.
testResults.failed[passedFile.name +
test_results.failed[passedFile.name +
' ***no results for entire test suite***'] = 100
testenv = localenv.Clone()
@@ -94,7 +94,7 @@ def addTestProgram(subdir, progName, env_vars={}):
mglob(testenv, subdir, 'cpp'))
passedFile = File(pjoin(str(program[0].dir), '%s.passed' % program[0].name))
PASSED_FILES[progName] = str(passedFile)
testResults.tests[passedFile.name] = program
test_results.tests[passedFile.name] = program
if env['googletest'] != 'none':
run_program = testenv.Command(passedFile, program, gtestRunner)
env.Depends(run_program, env['build_targets'])
@@ -102,7 +102,7 @@ def addTestProgram(subdir, progName, env_vars={}):
Alias('test-%s' % progName, run_program)
env['testNames'].append(progName)
else:
testResults.failed['test-%s (googletest disabled)' % progName] = 1
test_results.failed['test-%s (googletest disabled)' % progName] = 1
if os.path.exists(passedFile.abspath):
Alias('test-reset', testenv.Command('reset-%s%s' % (subdir, progName),
@@ -120,7 +120,7 @@ def addPythonTest(testname, subdir, script, interpreter, outfile,
"""Scons Action to run a test script using the specified interpreter"""
workDir = Dir('#test/work').abspath
passedFile = target[0]
testResults.tests.pop(passedFile.name, None)
test_results.tests.pop(passedFile.name, None)
if not os.path.isdir(workDir):
os.mkdir(workDir)
if os.path.exists(unittest_outfile):
@@ -154,9 +154,9 @@ def addPythonTest(testname, subdir, script, interpreter, outfile,
for line in open(outfile):
status, name = line.strip().split(': ', 1)
if status == 'PASS':
testResults.passed[':'.join((testname,name))] = 1
test_results.passed[':'.join((testname,name))] = 1
elif status in ('FAIL', 'ERROR'):
testResults.failed[':'.join((testname,name))] = 1
test_results.failed[':'.join((testname,name))] = 1
failures += 1
elif os.path.exists(pytest_outfile):
results = ElementTree.parse(pytest_outfile)
@@ -166,15 +166,15 @@ def addPythonTest(testname, subdir, script, interpreter, outfile,
class_name = class_name[26:]
test_name = "python: {}.{}".format(class_name, test.get('name'))
if test.findall('failure'):
testResults.failed[test_name] = 1
test_results.failed[test_name] = 1
failures += 1
else:
testResults.passed[test_name] = 1
test_results.passed[test_name] = 1
if code and failures == 0:
# Failure, but unable to determine status of individual tests. This
# gets counted as many failures.
testResults.failed[testname +
test_results.failed[testname +
' ***no results for entire test suite***'] = 100
testenv = localenv.Clone()
@@ -188,7 +188,7 @@ def addPythonTest(testname, subdir, script, interpreter, outfile,
testenv.Depends(run_program, dep)
if not optional:
testenv.Depends(env['test_results'], run_program)
testResults.tests[passedFile.name] = True
test_results.tests[passedFile.name] = True
if os.path.exists(passedFile.abspath):
Alias('test-reset', testenv.Command('reset-%s%s' % (subdir, testname),
[], [Delete(passedFile.abspath)]))
@@ -199,7 +199,7 @@ def addPythonTest(testname, subdir, script, interpreter, outfile,
def addMatlabTest(script, testName, dependencies=None, env_vars=()):
def matlabRunner(target, source, env):
passedFile = target[0]
del testResults.tests[passedFile.name]
del test_results.tests[passedFile.name]
workDir = Dir('#test/work').abspath
if not os.path.isdir(workDir):
os.mkdir(workDir)
@@ -224,7 +224,7 @@ def addMatlabTest(script, testName, dependencies=None, env_vars=()):
with open(outfile, "r") as output_file:
results = output_file.read()
except EnvironmentError: # TODO: replace with 'FileNotFoundError' after end of Python 2.7 support
testResults.failed['Matlab' +
test_results.failed['Matlab' +
' ***no results for entire test suite***'] = 100
return
@@ -245,10 +245,10 @@ def addMatlabTest(script, testName, dependencies=None, env_vars=()):
elif label == section: # skip summary line for each section
continue
elif 'FAILED' in line:
testResults.failed['.'.join(['Matlab', section, label])] = 1
test_results.failed['.'.join(['Matlab', section, label])] = 1
passed = False
elif 'passed' in line:
testResults.passed['.'.join(['Matlab', section, label])] = 1
test_results.passed['.'.join(['Matlab', section, label])] = 1
if passed:
open(target[0].path, 'w').write(time.asctime()+'\n')
@@ -256,7 +256,7 @@ def addMatlabTest(script, testName, dependencies=None, env_vars=()):
testenv = localenv.Clone()
passedFile = File('matlab/%s.passed' % (script))
PASSED_FILES[testName] = str(passedFile)
testResults.tests[passedFile.name] = True
test_results.tests[passedFile.name] = True
run_program = testenv.Command(passedFile, pjoin('matlab', script), matlabRunner)
dependencies = (dependencies or []) + localenv['matlab_extension']

View File

@@ -58,7 +58,7 @@ class Test(object):
self.passedFile = '.passed-%s' % testName
PASSED_FILES[self.testName] = pjoin(self.subdir, self.passedFile)
testResults.tests[self.testName] = self
test_results.tests[self.testName] = self
if source_files:
self.program = localenv.Program(