Skip to content

Commit

Permalink
Add coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avirshup authored and Aaron Virshup committed May 23, 2017
1 parent d31752f commit e4fb894
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service_name: codeship

66 changes: 45 additions & 21 deletions deployment/codeship_runtests.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,64 @@
#!/usr/bin/env bash

# this script expects to run from the moldesign/_tests directory

function check_if_tests_should_run(){
echo "Should I run the tests in this environment?"

function shouldruntests(){
if [ "${TESTENV}" == "complete" ]; then
echo true
runthem=true
echo "YES: always run in 'complete' environment"
fi

case "${CI_BRANCH}" in
master|deploy|dev)
echo true
runthem=true
echo "YES: always run in branch \"${CI_BRANCH}\""
;;
esac

if [[ "${CI_COMMIT_MESSAGE}" == *" --testall "* ]]; then
echo true
if [[ "${CI_COMMIT_MESSAGE}" == *"--testall"* ]]; then
runthem=true
echo "YES: found \"--testall\" flag in commit message"
fi

echo false
if [ "${runthem}" != "true" ]; then
echo "SKIPPING tests in this environment."
echo "To run these tests, add \"--testall\" to your commit message"
echo "(or work in the dev or deploy branches)"
python ../../deployment/send_test_status.py 0 "Skipped (dev/deploy branches only)"
exit 0
fi
}

if [ $(shouldruntests) == false ]; then
echo "SKIPPING minimal environment tests for this commit."
echo "To run these tests, add \"--testall\" to your commit message"
echo "(or work in the dev or deploy branches)"
python ../../deployment/send_test_status.py 0 "Skipped (dev/deploy branches only)"
exit 0
else
py.test -n 4 --junit-xml=/opt/reports/junit.${TESTENV}.xml | tee /opt/reports/pytest.${TESTENV}.log
exitstat=${PIPESTATUS[0]}

statline="$(tail -n1 /opt/reports/pytest.${TESTENV}.log)"
function run_tests(){
if [ "${TESTENV}" == "complete" ]; then
coverageflags="--cov .. --cov-report=term-missing:/opt/reports/coverage --cov-report="
fi

py.test -n 4 --junit-xml=/opt/reports/junit.${TESTENV}.xml $coverageflags | tee /opt/reports/pytest.${TESTENV}.log
exitstat=${PIPESTATUS[0]}

statline="$(tail -n1 /opt/reports/pytest.${TESTENV}.log)"

echo 'Test status:'
echo ${statline}
echo 'Test status:'
echo ${statline}

python ../../deployment/send_test_status.py ${exitstat} "${statline}"

if [ "${TESTENV}" == "complete" ]; then
if [ ${exitstat} -eq 0 ]; then
coveralls || echo "Failed to upload code coverage stats"
else
echo "Skipping coveralls upload: tests not passing."
coverage report
fi
fi

exit ${exitstat}
}

python ../../deployment/send_test_status.py ${exitstat} "${statline}"

exit ${exitstat}
fi
check_if_tests_should_run
run_tests
5 changes: 5 additions & 0 deletions moldesign/_tests/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
omit =
../_notebooks/
../_static_data/
../_tests/

0 comments on commit e4fb894

Please sign in to comment.