2012-03-19 21:25:20 +11:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-12-19 17:27:49 +00:00
|
|
|
BASE_DIR=`dirname $0`
|
|
|
|
|
2012-03-19 21:25:20 +11:00
|
|
|
function usage {
|
2012-12-20 11:24:12 +00:00
|
|
|
echo "Usage: $0 [OPTION]..."
|
|
|
|
echo "Run Heat's test suite(s)"
|
|
|
|
echo ""
|
2012-12-20 15:37:29 +00:00
|
|
|
echo " -V, --virtual-env Use virtualenv. Install automatically if not present."
|
|
|
|
echo " (Default is to run tests in local environment)"
|
2012-12-20 11:24:12 +00:00
|
|
|
echo " -F, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
|
2013-04-27 08:37:41 -07:00
|
|
|
echo " -f, --func Functional tests have been removed."
|
2012-12-20 11:24:12 +00:00
|
|
|
echo " -u, --unit Run unit tests (default when nothing specified)"
|
2014-02-17 23:16:17 -05:00
|
|
|
echo " -p, --pep8 Run flake8 and HACKING compliance check (default when nothing specified)"
|
2014-01-28 15:18:38 +01:00
|
|
|
echo " -P, --no-pep8 Don't run flake8 and HACKING compliance check"
|
2013-04-27 08:37:41 -07:00
|
|
|
echo " --all Run pep8 and unit tests"
|
|
|
|
echo " -c, --coverage Generate coverage report"
|
2013-08-13 02:33:50 +08:00
|
|
|
echo " -d, --debug Run tests with testtools instead of testr. This allows you to use the debugger."
|
2012-12-20 11:24:12 +00:00
|
|
|
echo " -h, --help Print this usage message"
|
|
|
|
exit
|
2012-03-19 21:25:20 +11:00
|
|
|
}
|
|
|
|
|
2012-08-29 13:30:47 -04:00
|
|
|
# must not assign -a as an option, needed for selecting custom attributes
|
2012-12-20 15:37:29 +00:00
|
|
|
no_venv=1
|
2012-03-19 21:25:20 +11:00
|
|
|
function process_option {
|
2012-12-20 11:24:12 +00:00
|
|
|
case "$1" in
|
2012-12-20 15:37:29 +00:00
|
|
|
-V|--virtual-env) no_venv=0;;
|
2012-12-20 11:24:12 +00:00
|
|
|
-F|--force) force=1;;
|
2013-04-27 08:37:41 -07:00
|
|
|
-f|--func) test_func=1;;
|
|
|
|
-u|--unit) test_unit=1;;
|
2012-12-20 11:24:12 +00:00
|
|
|
-p|--pep8) test_pep8=1;;
|
2014-01-28 15:18:38 +01:00
|
|
|
-P|--no-pep8) test_pep8=0;;
|
2013-04-27 08:37:41 -07:00
|
|
|
--all) test_unit=1; test_pep8=1;;
|
|
|
|
-c|--coverage) coverage=1;;
|
2013-08-13 02:33:50 +08:00
|
|
|
-d|--debug) debug=1;;
|
2012-12-20 11:24:12 +00:00
|
|
|
-h|--help) usage;;
|
2013-04-27 08:37:41 -07:00
|
|
|
*) args="$args $1"; test_unit=1;;
|
2012-12-20 11:24:12 +00:00
|
|
|
esac
|
2012-03-19 21:25:20 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
venv=.venv
|
|
|
|
with_venv=tools/with_venv.sh
|
|
|
|
wrapper=""
|
2013-08-13 02:33:50 +08:00
|
|
|
debug=0
|
2014-03-29 23:47:20 +02:00
|
|
|
flake8args="heat bin/heat-api bin/heat-api-cfn bin/heat-api-cloudwatch bin/heat-engine bin/heat-manage contrib"
|
2012-03-19 21:25:20 +11:00
|
|
|
|
|
|
|
function run_tests {
|
2012-12-20 11:24:12 +00:00
|
|
|
echo 'Running tests'
|
2013-05-29 09:25:30 +02:00
|
|
|
# Remove any extraneous DB migrations
|
|
|
|
find heat/db/sqlalchemy/migrate_repo/versions/ -name '*.pyc' -delete
|
2013-08-13 02:33:50 +08:00
|
|
|
|
|
|
|
if [ $debug -eq 1 ]; then
|
|
|
|
echo "Debugging..."
|
|
|
|
if [ "$args" = "" ]; then
|
|
|
|
# Default to running all tests if specific test is not
|
|
|
|
# provided.
|
|
|
|
testrargs="discover ./heat/tests"
|
|
|
|
fi
|
|
|
|
${wrapper} python -m testtools.run $args $testrargs
|
|
|
|
|
|
|
|
# Short circuit because all of the testr and coverage stuff
|
|
|
|
# below does not make sense when running testtools.run for
|
|
|
|
# debugging purposes.
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
|
2012-12-20 11:24:12 +00:00
|
|
|
# Just run the test suites in current environment
|
2013-04-27 08:37:41 -07:00
|
|
|
if [ -n "$args" ] ; then
|
|
|
|
args="-t $args"
|
|
|
|
fi
|
2013-12-02 10:50:36 -03:00
|
|
|
${wrapper} python setup.py testr --slowest $args
|
2012-03-19 21:25:20 +11:00
|
|
|
}
|
|
|
|
|
2012-04-13 17:10:30 -04:00
|
|
|
function run_pep8 {
|
2013-05-11 14:26:42 -04:00
|
|
|
echo "Running flake8..."
|
2014-03-29 23:47:20 +02:00
|
|
|
bash -c "${wrapper} flake8 ${flake8args}"
|
2012-04-13 17:10:30 -04:00
|
|
|
}
|
2012-03-19 21:25:20 +11:00
|
|
|
|
2012-08-31 13:49:40 +01:00
|
|
|
# run unit tests with pep8 when no arguments are specified
|
|
|
|
# otherwise process CLI options
|
|
|
|
if [[ $# == 0 ]]; then
|
|
|
|
test_pep8=1
|
2013-04-27 08:37:41 -07:00
|
|
|
test_unit=1
|
2012-08-31 13:49:40 +01:00
|
|
|
else
|
|
|
|
for arg in "$@"; do
|
|
|
|
process_option $arg
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2012-12-20 15:37:29 +00:00
|
|
|
if [ "$no_venv" == 0 ]
|
2012-03-19 21:25:20 +11:00
|
|
|
then
|
2012-12-20 11:24:12 +00:00
|
|
|
# Remove the virtual environment if --force used
|
|
|
|
if [ "$force" == 1 ]; then
|
|
|
|
echo "Cleaning virtualenv..."
|
|
|
|
rm -rf ${venv}
|
|
|
|
fi
|
|
|
|
if [ -e ${venv} ]; then
|
|
|
|
wrapper="${with_venv}"
|
2012-03-19 21:25:20 +11:00
|
|
|
else
|
2012-12-20 15:37:29 +00:00
|
|
|
# Automatically install the virtualenv
|
|
|
|
python tools/install_venv.py
|
|
|
|
wrapper="${with_venv}"
|
2012-03-19 21:25:20 +11:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-09-18 13:15:06 +02:00
|
|
|
result=0
|
|
|
|
|
2012-08-31 13:49:40 +01:00
|
|
|
# If functional or unit tests have been selected, run them
|
2013-08-13 02:33:50 +08:00
|
|
|
if [ "$test_unit" == 1 ] || [ "$debug" == 1 ] ; then
|
2012-12-20 11:24:12 +00:00
|
|
|
run_tests
|
|
|
|
result=$?
|
2012-04-13 17:10:30 -04:00
|
|
|
fi
|
|
|
|
|
2012-08-31 13:49:40 +01:00
|
|
|
# Run pep8 if it was selected
|
|
|
|
if [ "$test_pep8" == 1 ]; then
|
2012-12-20 11:24:12 +00:00
|
|
|
run_pep8
|
2012-05-08 11:31:25 -04:00
|
|
|
fi
|
2012-04-13 17:10:30 -04:00
|
|
|
|
2012-08-31 13:49:40 +01:00
|
|
|
# Generate coverage report
|
2012-08-29 13:30:47 -04:00
|
|
|
if [ "$coverage" == 1 ]; then
|
2013-04-27 08:37:41 -07:00
|
|
|
echo "Generating coverage report in ./cover"
|
2013-12-02 10:50:36 -03:00
|
|
|
${wrapper} python setup.py testr --coverage --slowest
|
|
|
|
${wrapper} python -m coverage report --show-missing
|
2012-05-08 11:31:25 -04:00
|
|
|
fi
|
2012-09-18 13:15:06 +02:00
|
|
|
|
|
|
|
exit $result
|