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

Refactor run tests #114

Merged
merged 3 commits into from
Jul 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lines with piped commands requires that the script sets the pipefail option:
set -o pipefail

Otherwise the variable $? always holds the exit status of the last command, which means a failure of pep-it.sh would be ignored.

display_result $? 3 "Code style check"