summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/contributing.md15
-rwxr-xr-xrun_tests.sh172
2 files changed, 82 insertions, 105 deletions
diff --git a/docs/contributing.md b/docs/contributing.md
index 1b95496..00384c5 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -28,9 +28,22 @@ To run tests:
./run_tests.sh --pep8 # pep8 checks
./run_tests.sh --stats # print some code stats
./run_tests.sh --git # inception: run gitlint against itself
-./run_tests.sh --lint # run pylint checks
+./run_tests.sh --all # Run unit, integration, pep8 and gitlint checks
+./run_tests.sh --lint # run pylint checks (only supported on python 2.7)
```
+The ```Vagrantfile``` comes with ```virtualenv```s for python 2.6, 2.7, 3.3, 3.4 and 3.5.
+You can easily run tests against specific python environments by using the following commands *inside* of the Vagrant VM:
+```
+./run_tests.sh --envs 26 # Run the unit tests against Python 2.6
+./run_tests.sh --envs 27,33 # Run the unit tests against Python 2.7 and Python 3.3
+./run_tests.sh --envs 27,33 --pep8 # Run pep8 checks against Python 2.7 and Python 3.3 (also works for ```--git```, ```--integration```, ```--pep8```, ```--stats``` and ```--lint```).
+./run_tests.sh --envs all --all # Run all tests against all environments
+./run_tests.sh --all-env --all # Idem: Run all tests against all environments
+```
+
+### Packaging ###
+
To see the package description in HTML format
```
pip install docutils
diff --git a/run_tests.sh b/run_tests.sh
index 7a8f306..f9551a7 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -1,20 +1,23 @@
-#!/bin/bash -e
+#!/bin/bash
+
help(){
echo "Usage: $0 [OPTION]..."
echo "Run gitlint's test suite(s) or some convience commands"
- echo " -h, --help Show this help output"
- echo " -c, --clean Clean the project of temporary files"
- echo " -p, --pep8 Run pep8 checks"
- echo " -l, --lint Run pylint checks"
- echo " -g, --git Run gitlint checks"
- echo " -i, --integration Run integration tests"
- echo " -a, --all Run all tests and checks (unit, integration, pep8, git)"
- echo " --all-env Run all tests against all python environments"
- echo " --install-virtualenvs Install virtualenvs for python 2.6, 2.7, 3.3, 3.4, 3.5"
- echo " --remove-virtualenvs Remove virtualenvs for python 2.6, 2.7, 3.3, 3.4, 3.5"
- echo " -s, --stats Show some project stats"
- echo " --no-coverage Don't make a unit test coverage report"
+ echo " -h, --help Show this help output"
+ echo " -c, --clean Clean the project of temporary files"
+ echo " -p, --pep8 Run pep8 checks"
+ echo " -l, --lint Run pylint checks"
+ echo " -g, --git Run gitlint checks"
+ echo " -i, --integration Run integration tests"
+ echo " -a, --all Run all tests and checks (unit, integration, pep8, git)"
+ echo " -e, --envs [ENV1],[ENV2] Run tests against specified environments (envs: 26,27,33,34,35)."
+ echo " Also works for integration, pep8 and lint tests."
+ echo " --all-env Run all tests against all python environments"
+ echo " --install-virtualenvs Install virtualenvs for python 2.6, 2.7, 3.3, 3.4, 3.5"
+ echo " --remove-virtualenvs Remove virtualenvs for python 2.6, 2.7, 3.3, 3.4, 3.5"
+ echo " -s, --stats Show some project stats"
+ echo " --no-coverage Don't make a unit test coverage report"
echo ""
exit 0;
}
@@ -65,9 +68,7 @@ run_unit_tests(){
echo "$COVERAGE_REPORT"
fi
- if [ $TEST_RESULT -gt 0 ]; then
- exit $TEST_RESULT;
- fi
+ return $TEST_RESULT;
}
run_integration_tests(){
@@ -106,11 +107,9 @@ run_stats(){
clean(){
echo -n "Cleaning the site, build, dist and all __pycache__directories..."
- set +e
find gitlint -type d -name "__pycache__" -exec rm -rf {} \; 2> /dev/null
find qa -type d -name "__pycache__" -exec rm -rf {} \; 2> /dev/null
rm -rf "site" "dist" "build"
- set -e
echo -e "${GREEN}DONE${NO_COLOR}"
}
@@ -126,9 +125,7 @@ run_all(){
remove_virtualenvs(){
echo -n "Removing .venv26 .venv27 .venv33 .venv34 .venv35..."
- set +e
deactivate 2> /dev/null # deactivate any active environment
- set -e
rm -rf ".venv26" ".venv27" ".venv33" ".venv34" ".venv35"
echo -e "${GREEN}DONE${NO_COLOR}"
}
@@ -136,9 +133,7 @@ remove_virtualenvs(){
install_virtualenvs(){
echo "Installing .venv26 .venv27 .venv33 .venv34 .venv35..."
- set +e
deactivate 2> /dev/null # deactivate any active environment
- set -e
# Install the virtualenvs for different python versions
virtualenv -p /usr/bin/python2.6 .venv26
@@ -174,43 +169,9 @@ install_virtualenvs(){
deactivate
}
-run_tests_in_all_env(){
- # Let's make sure we can recover the current virtualenv after we're done
- old_virtualenv="$VIRTUAL_ENV"
- set +e
- deactivate 2> /dev/null # deactivate any active environment
- set -e
-
- # Run the tests against all environments in vagrant
- source /vagrant/.venv26/bin/activate
- title "### PYTHON 2.6 ($(python --version 2>&1), /vagrant/.venv26) ###"
- run_all
- deactivate
-
- source /vagrant/.venv27/bin/activate
- title "### PYTHON 2.7 ($(python --version 2>&1), /vagrant/.venv27) ###"
- run_all
- deactivate
-
- source /vagrant/.venv33/bin/activate
- title "### PYTHON 3.3 ($(python --version 2>&1), /vagrant/.venv33) ###"
- run_all
- deactivate
-
- source /vagrant/.venv34/bin/activate
- title "### PYTHON 3.4 ($(python --version 2>&1), /vagrant/.venv34) ###"
- run_all
- deactivate
+##############################################################################
+# The magic starts here: argument parsing and determining what to do
- source /vagrant/.venv35/bin/activate
- title "### PYTHON 3.5 ($(python --version 2>&1), /vagrant/.venv35) ###"
- run_all
- deactivate
-
- if [ ! -z "$old_virtualenv" ]; then
- source "$old_virtualenv/bin/activate"
- fi
-}
# default behavior
just_pep8=0
@@ -218,12 +179,12 @@ just_lint=0
just_git=0
just_integration_tests=0
just_stats=0
-just_all_env=0
just_all=0
just_clean=0
just_install_virtualenvs=0
just_remove_virtualenvs=0
include_coverage=1
+envs="default"
testargs=""
while [ "$#" -gt 0 ]; do
@@ -236,63 +197,66 @@ while [ "$#" -gt 0 ]; do
-s|--stats) shift; just_stats=1;;
-i|--integration) shift; just_integration_tests=1;;
-a|--all) shift; just_all=1;;
+ -e|--envs) shift; envs="$1"; shift;;
--install-virtualenvs) shift; just_install_virtualenvs=1;;
--remove-virtualenvs) shift; just_remove_virtualenvs=1;;
- --all-env) shift; just_all_env=1;;
+ --all-env) shift; envs="all";;
--no-coverage)shift; include_coverage=0;;
*) testargs="$1"; shift;
esac
done
-if [ $just_pep8 -eq 1 ]; then
- run_pep8_check
- exit $?
-fi
-
-if [ $just_stats -eq 1 ]; then
- run_stats
- exit $?
-fi
-
-if [ $just_integration_tests -eq 1 ]; then
- run_integration_tests
- exit $?
-fi
-
-if [ $just_git -eq 1 ]; then
- run_git_check
- exit $?
-fi
-
-if [ $just_lint -eq 1 ]; then
- run_lint_check
- exit $?
-fi
+old_virtualenv="$VIRTUAL_ENV" # Store the current virtualenv so we can restore it at the end
+trap exit INT # Exit on interrupt (i.e. ^C)
-if [ $just_all_env -eq 1 ]; then
- run_tests_in_all_env
- exit $?
-fi
+exit_code=0
-if [ $just_all -eq 1 ]; then
- run_all
- exit $?
+# If the users specified 'all', then just replace $envs with the list of all envs
+if [ "$envs" == "all" ]; then
+ envs="26,27,33,34,35"
fi
+envs=$(echo "$envs" | tr ',' '\n') # Split the env list on comma so we can loop through it
-if [ $just_clean -eq 1 ]; then
- clean
- exit $?
-fi
-if [ $just_remove_virtualenvs -eq 1 ]; then
- remove_virtualenvs
- exit $?
-fi
+for environment in $envs; do
+ if [ "$environment" != "default" ]; then
+ deactivate 2> /dev/null # deactivate any active environment
+ set -e # Let's error out if you try executing against a non-existing env
+ source "/vagrant/.venv$environment/bin/activate"
+ set +e
+ fi
+ title "### PYTHON ($(python --version 2>&1), $(which python)) ###"
+
+ if [ $just_pep8 -eq 1 ]; then
+ run_pep8_check
+ elif [ $just_stats -eq 1 ]; then
+ run_stats
+ elif [ $just_integration_tests -eq 1 ]; then
+ run_integration_tests
+ elif [ $just_git -eq 1 ]; then
+ run_git_check
+ elif [ $just_lint -eq 1 ]; then
+ run_lint_check
+ elif [ $just_all -eq 1 ]; then
+ run_all
+ elif [ $just_clean -eq 1 ]; then
+ clean
+ elif [ $just_remove_virtualenvs -eq 1 ]; then
+ remove_virtualenvs
+ elif [ $just_install_virtualenvs -eq 1 ]; then
+ install_virtualenvs
+ else
+ run_unit_tests
+ fi
+ # We add up all the exit codes and use that as our final exit code
+ # While we lose the meaning of the exit code per individual environment by doing this, we do ensure that the end
+ # exit code reflects success (=0) or failure (>0).
+ exit_code=$((exit_code + $?))
+done
-if [ $just_install_virtualenvs -eq 1 ]; then
- install_virtualenvs
- exit $?
+# reactivate the virtualenv if we had one before
+if [ ! -z "$old_virtualenv" ]; then
+ source "$old_virtualenv/bin/activate"
fi
-
-run_unit_tests || exit
+exit $exit_code