summaryrefslogtreecommitdiff
path: root/run_tests.sh
diff options
context:
space:
mode:
authorAkihiro Motoki <motoki@da.jp.nec.com>2014-08-20 00:34:40 +0900
committerAkihiro Motoki <motoki@da.jp.nec.com>2014-08-24 07:34:53 +0900
commite63ff5eab0d1924a795fc5e07a2f776ecdcbfee8 (patch)
tree928fe1066fa691d2387fd97df56e4552a5780654 /run_tests.sh
parentbf0c4aa49edeb3ba1e94d37fa0cd831780b3d06d (diff)
downloadhorizon-e63ff5eab0d1924a795fc5e07a2f776ecdcbfee8.tar.gz
Provide a quick way to run flake8
"run_tests.sh -p" always checks every file for errors even though you have probably only changed a handful. This patch adds "run_tests.sh -8" which only checks the files that were modified in the HEAD commit or the current working tree. It is borrowed from the recent nova commit b011325cc6. The related ML post is: http://lists.openstack.org/pipermail/openstack-dev/2014-August/043346.html Change-Id: If3c8e5e3e442257f796374edba02c3a23a85839e
Diffstat (limited to 'run_tests.sh')
-rwxr-xr-xrun_tests.sh32
1 files changed, 30 insertions, 2 deletions
diff --git a/run_tests.sh b/run_tests.sh
index 85fc11085..001bcf459 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -25,6 +25,9 @@ function usage {
echo " --makemessages Create/Update English translation files."
echo " --compilemessages Compile all translation files."
echo " -p, --pep8 Just run pep8"
+ echo " -8, --pep8-changed [<basecommit>]"
+ echo " Just run PEP8 and HACKING compliance check"
+ echo " on files changed since HEAD~1 (or <basecommit>)"
echo " -P, --no-pep8 Don't run pep8 by default"
echo " -t, --tabs Check for tab characters in files."
echo " -y, --pylint Just run pylint"
@@ -65,6 +68,7 @@ command_wrapper=""
destroy=0
force=0
just_pep8=0
+just_pep8_changed=0
no_pep8=0
just_pylint=0
just_docs=0
@@ -100,6 +104,7 @@ function process_option {
-V|--virtual-env) always_venv=1; never_venv=0;;
-N|--no-virtual-env) always_venv=0; never_venv=1;;
-p|--pep8) just_pep8=1;;
+ -8|--pep8-changed) just_pep8_changed=1;;
-P|--no-pep8) no_pep8=1;;
-y|--pylint) just_pylint=1;;
-j|--jshint) just_jshint=1;;
@@ -154,8 +159,7 @@ function run_jshint {
jshint horizon/static/horizon/tests
}
-function run_pep8 {
- echo "Running flake8 ..."
+function warn_on_flake8_without_venv {
set +o errexit
${command_wrapper} python -c "import hacking" 2>/dev/null
no_hacking=$?
@@ -165,9 +169,28 @@ function run_pep8 {
echo "OpenStack hacking is not installed on your host. Its detection will be missed." >&2
echo "Please install or use virtual env if you need OpenStack hacking detection." >&2
fi
+}
+
+function run_pep8 {
+ echo "Running flake8 ..."
+ warn_on_flake8_without_venv
DJANGO_SETTINGS_MODULE=openstack_dashboard.test.settings ${command_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 base_commit=${testargs:-HEAD~1}
+ files=$(git diff --name-only $base_commit | tr '\n' ' ')
+ echo "Running flake8 on ${files}"
+ warn_on_flake8_without_venv
+ diff -u --from-file /dev/null ${files} | DJANGO_SETTINGS_MODULE=openstack_dashboard.test.settings ${command_wrapper} flake8 --diff
+ exit
+}
+
function run_sphinx {
echo "Building sphinx..."
DJANGO_SETTINGS_MODULE=openstack_dashboard.test.settings ${command_wrapper} python setup.py build_sphinx
@@ -495,6 +518,11 @@ if [ $just_pep8 -eq 1 ]; then
exit $?
fi
+if [ $just_pep8_changed -eq 1 ]; then
+ run_pep8_changed
+ exit $?
+fi
+
# Pylint
if [ $just_pylint -eq 1 ]; then
run_pylint