Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #114 from alphagov/refactor-run-tests
Browse files Browse the repository at this point in the history
Refactor run tests
  • Loading branch information
maxfliri committed Jul 9, 2013
2 parents 211c595 + cdef7d1 commit 370b527
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 51 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ services: mongodb
install: "pip install -q -r requirements_for_tests.txt --use-mirrors"
# command to run tests
script:
- nosetests --with-coverage --cover-inclusive
- behave --stop --tags=-wip
- ./pep-it.sh
- ./run_tests.sh
after_script:
- coveralls
branches:
Expand Down
28 changes: 1 addition & 27 deletions jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,10 @@

set -o pipefail

function display_result {
RESULT=$1
EXIT_STATUS=$2
TEST=$3

if [ $RESULT -ne 0 ]; then
echo "$TEST failed"
exit $EXIT_STATUS
else
echo "$TEST passed"
fi
}

VIRTUALENV_DIR=/var/tmp/virtualenvs/$(echo ${JOB_NAME} | tr ' ' '-')
export PIP_DOWNLOAD_CACHE=/var/tmp/pip_download_cache

virtualenv --clear --no-site-packages $VIRTUALENV_DIR
source $VIRTUALENV_DIR/bin/activate

pip install -r requirements_for_tests.txt

rm -f coverage.xml .coverage nosetests.xml
find . -name '*.pyc' -delete

nosetests -v --with-xunit --with-coverage --cover-package=backdrop --cover-inclusive
display_result $? 1 "Unit tests"
python -m coverage.__main__ xml --include=backdrop*

behave --tags=-wip --stop
display_result $? 2 "Feature tests"

$(dirname $0)/pep-it.sh | tee pep8.out
display_result $? 3 "Code style check"
./run_tests.sh
46 changes: 25 additions & 21 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
#!/bin/bash

set -o pipefail

function display_result {
RESULT=$1
EXIT_STATUS=$2
TEST=$3

if [ $RESULT -ne 0 ]; then
echo
echo -e "\033[31m$TEST failed\033[0m"
echo
exit $EXIT_STATUS
else
echo
echo -e "\033[32m$TEST passed\033[0m"
echo
fi
RESULT=$1
EXIT_STATUS=$2
TEST=$3

if [ $RESULT -ne 0 ]; then
echo -e "\033[31m$TEST failed\033[0m"
exit $EXIT_STATUS
else
echo -e "\033[32m$TEST passed\033[0m"
fi
}
basedir=$(dirname $0)
venvdir=~/.virtualenvs/$(basename $(cd $(dirname $0) && pwd -P))

if [ ! -d $venvdir ]; then
virtualenv $venvdir
# If you're not already in a virtualenv and you're using virtualenvwrapper
if [ -z "$VIRTUAL_ENV" -a -n "$WORKON_HOME" ]; then
basedir=$(dirname $0)
venvdir=$WORKON_HOME/$(basename $(cd $(dirname $0) && pwd -P))

if [ ! -d "$venvdir" ]; then
virtualenv $venvdir
fi

source "$venvdir/bin/activate"
fi

source "$venvdir/bin/activate"

pip install -r requirements_for_tests.txt

rm -f coverage.xml .coverage nosetests.xml
find . -name '*.pyc' -delete

nosetests -v
nosetests -v --with-xunit --with-coverage --cover-package=backdrop --cover-inclusive
display_result $? 1 "Unit tests"

behave --stop --tags=-wip
display_result $? 2 "Feature tests"

"$basedir/pep-it.sh"
./pep-it.sh | tee pep8.out
display_result $? 3 "Code style check"

0 comments on commit 370b527

Please sign in to comment.