Use argparse in run_tests.py instead of optparse

This commit is contained in:
Paul Romano 2017-09-29 09:45:42 -05:00
parent d84bd669f2
commit 7653be0a5e

View file

@ -10,35 +10,35 @@ import glob
import socket
from subprocess import call, check_output
from collections import OrderedDict
from optparse import OptionParser
from argparse import ArgumentParser
# Command line parsing
parser = OptionParser()
parser.add_option('-j', '--parallel', dest='n_procs', default='1',
parser = ArgumentParser()
parser.add_argument('-j', '--parallel', dest='n_procs', default='1',
help="Number of parallel jobs.")
parser.add_option('-R', '--tests-regex', dest='regex_tests',
parser.add_argument('-R', '--tests-regex', dest='regex_tests',
help="Run tests matching regular expression. \
Test names are the directories present in tests folder.\
This uses standard regex syntax to select tests.")
parser.add_option('-C', '--build-config', dest='build_config',
parser.add_argument('-C', '--build-config', dest='build_config',
help="Build configurations matching regular expression. \
Specific build configurations can be printed out with \
optional argument -p, --print. This uses standard \
regex syntax to select build configurations.")
parser.add_option('-l', '--list', action="store_true",
parser.add_argument('-l', '--list', action="store_true",
dest="list_build_configs", default=False,
help="List out build configurations.")
parser.add_option("-p", "--project", dest="project", default="",
parser.add_argument("-p", "--project", dest="project", default="",
help="project name for build")
parser.add_option("-D", "--dashboard", dest="dash",
parser.add_argument("-D", "--dashboard", dest="dash",
help="Dash name -- Experimental, Nightly, Continuous")
parser.add_option("-u", "--update", action="store_true", dest="update",
parser.add_argument("-u", "--update", action="store_true", dest="update",
help="Allow CTest to update repo. (WARNING: may overwrite\
changes that were not pushed.")
parser.add_option("-s", "--script", action="store_true", dest="script",
parser.add_argument("-s", "--script", action="store_true", dest="script",
help="Activate CTest scripting mode for coverage, valgrind\
and dashboard capability.")
(options, args) = parser.parse_args()
args = parser.parse_args()
# Default compiler paths
FC='gfortran'
@ -173,7 +173,7 @@ class Test(object):
# Sets the build name that will show up on the CDash
def get_build_name(self):
self.build_name = options.project + '_' + self.name
self.build_name = args.project + '_' + self.name
return self.build_name
# Sets up build options for various tests. It is used both
@ -246,9 +246,9 @@ class Test(object):
make_list = ['make','-s']
# Check for parallel
if options.n_procs is not None:
if args.n_procs is not None:
make_list.append('-j')
make_list.append(options.n_procs)
make_list.append(args.n_procs)
# Run make
rc = call(make_list)
@ -265,14 +265,14 @@ class Test(object):
ctest_list = ['ctest']
# Check for parallel
if options.n_procs is not None:
if args.n_procs is not None:
ctest_list.append('-j')
ctest_list.append(options.n_procs)
ctest_list.append(args.n_procs)
# Check for subset of tests
if options.regex_tests is not None:
if args.regex_tests is not None:
ctest_list.append('-R')
ctest_list.append(options.regex_tests)
ctest_list.append(args.regex_tests)
# Run ctests
rc = call(ctest_list)
@ -308,7 +308,7 @@ add_test('hdf5-debug_valgrind', debug=True, valgrind=True)
add_test('hdf5-debug_coverage', debug=True, coverage=True)
# Check to see if we should just print build configuration information to user
if options.list_build_configs:
if args.list_build_configs:
for key in tests:
print('Configuration Name: {0}'.format(key))
print(' Debug Flags:..........{0}'.format(tests[key].debug))
@ -320,10 +320,10 @@ if options.list_build_configs:
exit()
# Delete items of dictionary that don't match regular expression
if options.build_config is not None:
if args.build_config is not None:
to_delete = []
for key in tests:
if not re.search(options.build_config, key):
if not re.search(args.build_config, key):
to_delete.append(key)
for key in to_delete:
del tests[key]
@ -333,27 +333,21 @@ if options.build_config is not None:
# Experimental, Nightly, Continuous. On the CDash end, these can be
# reorganized into groups when a hostname, dashboard and build name
# are matched.
if options.dash is None:
if args.dash is None:
dash = 'Experimental'
submit = ''
else:
dash = options.dash
dash = args.dash
submit = 'ctest_submit()'
# Check for update command, which will run git fetch/merge and will delete
# any changes to repo that were not pushed to remote origin
if options.update:
update = 'ctest_update()'
else:
update = ''
update = 'ctest_update()' if args.update else ''
# Check for CTest scipts mode
# Sets up whether we should use just the basic ctest command or use
# CTest scripting to perform tests.
if not options.dash is None or options.script:
script_mode = True
else:
script_mode = False
script_mode = (args.dash is not None or args.script)
# Setup CTest script vars. Not used in non-script mode
pwd = os.getcwd()
@ -364,17 +358,17 @@ ctest_vars = {
'dashboard': dash,
'submit': submit,
'update': update,
'n_procs': options.n_procs
'n_procs': args.n_procs
}
# Check project name
subprop = """set_property(GLOBAL PROPERTY SubProject {0})"""
if options.project == "" :
ctest_vars.update({'subproject':''})
elif options.project == 'develop':
ctest_vars.update({'subproject':''})
subprop = "set_property(GLOBAL PROPERTY SubProject {0})"
if args.project == "" :
ctest_vars.update({'subproject': ''})
elif args.project == 'develop':
ctest_vars.update({'subproject': ''})
else:
ctest_vars.update({'subproject':subprop.format(options.project)})
ctest_vars.update({'subproject': subprop.format(args.project)})
# Set up default valgrind tests (subset of all tests)
# Currently takes too long to run all the tests with valgrind
@ -396,8 +390,8 @@ if not script_mode:
for key in to_delete:
del tests[key]
# Check if tests empty
if len(list(tests.keys())) == 0:
# Check if tests is empty
if not tests:
print('No tests to run.')
exit()
@ -447,7 +441,7 @@ for key in iter(tests):
# Check for user custom tests
# INCLUDE is a CTest command that allows for a subset
# of tests to be executed. Only used in script mode.
if options.regex_tests is None:
if args.regex_tests is None:
ctest_vars.update({'tests' : ''})
# No user tests, use default valgrind tests
@ -456,7 +450,7 @@ for key in iter(tests):
format(valgrind_default_tests)})
else:
ctest_vars.update({'tests' : 'INCLUDE {0}'.
format(options.regex_tests)})
format(args.regex_tests)})
# Main part of code that does the ctest execution.
# It is broken up by two modes, script and non-script