@ -14,6 +14,8 @@ function usage {
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
echo " -u, --update Update the virtual environment with any newer package versions"
echo " -p, --pep8 Just run PEP8 and HACKING compliance check"
echo " -8, --pep8-only-changed [<basecommit>]"
echo " Just run PEP8 and HACKING compliance check on files changed since HEAD~1 (or <basecommit>)"
echo " -P, --no-pep8 Don't run static code checks"
echo " -c, --coverage Generate coverage report"
echo " -d, --debug Run tests with testtools instead of testr. This allows you to use the debugger."
@ -44,6 +46,7 @@ function process_options {
-f| --force) force = 1; ;
-u| --update) update = 1; ;
-p| --pep8) just_pep8 = 1; ;
-8| --pep8-only-changed) just_pep8_changed = 1; ;
-P| --no-pep8) no_pep8 = 1; ;
-c| --coverage) coverage = 1; ;
-d| --debug) debug = 1; ;
@ -59,8 +62,8 @@ function process_options {
( ( i++ ) )
tools_path = ${ !i }
; ;
-*) test r opts= " $test r opts ${ !i } " ; ;
*) test r args= " $test r args ${ !i } "
-*) test opts= " $test opts ${ !i } " ; ;
*) test args= " $test args ${ !i } "
esac
( ( i++ ) )
done
@ -75,10 +78,11 @@ never_venv=0
force = 0
no_site_packages = 0
installvenvopts =
test r args=
test r opts=
test args=
test opts=
wrapper = ""
just_pep8 = 0
just_pep8_changed = 0
no_pep8 = 0
coverage = 0
debug = 0
@ -107,12 +111,12 @@ function run_tests {
${ wrapper } find . -type f -name "*.pyc" -delete
if [ $debug -eq 1 ] ; then
if [ " $test r opts" = "" ] && [ " $test r args" = "" ] ; then
if [ " $test opts" = "" ] && [ " $test args" = "" ] ; then
# Default to running all tests if specific test is not
# provided.
test r args= "discover ./neutron/tests"
test args= "discover ./neutron/tests"
fi
${ wrapper } python -m testtools.run $test r opts $test r args
${ wrapper } python -m testtools.run $test opts $test args
# Short circuit because all of the testr and coverage stuff
# below does not make sense when running testtools.run for
@ -128,9 +132,9 @@ function run_tests {
# Just run the test suites in current environment
set +e
test r args= ` echo " $test r args" | sed -e's/^\s*\(.*\)\s*$/\1/' `
TESTRTESTS = " $TESTRTESTS --testr-args='--subunit $test r opts $test r args' "
OS_TEST_PATH = ` echo $test r args| grep -o 'neutron\.tests[^[:space:]:]*\+' | tr . /`
test args= ` echo " $test args" | sed -e's/^\s*\(.*\)\s*$/\1/' `
TESTRTESTS = " $TESTRTESTS --testr-args='--subunit $test opts $test args' "
OS_TEST_PATH = ` echo $test args| grep -o 'neutron\.tests[^[:space:]:]*\+' | tr . /`
if [ -d " $OS_TEST_PATH " ] ; then
wrapper = " OS_TEST_PATH= $OS_TEST_PATH $wrapper "
elif [ -d " $( dirname $OS_TEST_PATH ) " ] ; then
@ -160,12 +164,32 @@ function copy_subunit_log {
cp $LOGNAME subunit.log
}
function warn_on_flake8_without_venv {
if [ $never_venv -eq 1 ] ; then
echo "**WARNING**:"
echo "Running flake8 without virtual env may miss OpenStack HACKING detection"
fi
}
function run_pep8 {
echo "Running flake8 ..."
warn_on_flake8_without_venv
${ wrapper } flake8
}
function run_pep8_changed {
# NOTE(gilliard) We want use flake8 to check the entirety of every file that has
# a change in it. Unfortunately the --filenames argument to flake8 only accepts
# file *names* and there are no files named (eg) "nova/compute/manager.py". The
# --diff argument behaves surprisingly as well, because although you feed it a
# diff, it actually checks the file on disk anyway.
local target = ${ testargs :- HEAD ~1 }
local files = $( git diff --name-only $target | tr '\n' ' ' )
echo " Running flake8 on ${ files } "
warn_on_flake8_without_venv
diff -u --from-file /dev/null ${ files } | ${ wrapper } flake8 --diff
}
TESTRTESTS = "python -m neutron.openstack.common.lockutils python setup.py testr"
@ -209,6 +233,11 @@ if [ $just_pep8 -eq 1 ]; then
exit
fi
if [ $just_pep8_changed -eq 1 ] ; then
run_pep8_changed
exit
fi
if [ $recreate_db -eq 1 ] ; then
rm -f tests.sqlite
fi
@ -217,9 +246,9 @@ run_tests
# NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
# not when we're running tests individually. To handle this, we need to
# distinguish between options (test r opts), which begin with a '-', and
# arguments (test r args).
if [ -z " $test r args" ] ; then
# distinguish between options (test opts), which begin with a '-', and
# arguments (test args).
if [ -z " $test args" ] ; then
if [ $no_pep8 -eq 0 ] ; then
run_pep8
fi