From 4decd8b14ae743a7f130323e0fac64f7e66041b3 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Fri, 17 Apr 2015 01:07:55 +0300 Subject: [PATCH] Make coverage job voting Instead of asking people to write unit tests let's just make coverage job voting. This can be implemented in very simple maner: 1) checkout to master 2) run coverage and get base line 3) checkout back 4) run coverage to get current coverage 5) If coverage was reduced more then 0.01% mark job as failed Change-Id: Ib6bc4dbb11c69b107e6fcd6464a4041337ea1a66 --- .coveragerc | 2 +- tests/ci/cover.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ tox.ini | 3 ++- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100755 tests/ci/cover.sh diff --git a/.coveragerc b/.coveragerc index e9342f81..67d82be5 100644 --- a/.coveragerc +++ b/.coveragerc @@ -4,4 +4,4 @@ source = rally [report] ignore-errors = True -precision = 2 +precision = 3 diff --git a/tests/ci/cover.sh b/tests/ci/cover.sh new file mode 100755 index 00000000..4e352cf5 --- /dev/null +++ b/tests/ci/cover.sh @@ -0,0 +1,47 @@ +#!/bin/bash -e +# +# Copyright 2015: Mirantis Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +# Checkout to master to collect base line coverage +git stash +git checkout master + +python setup.py testr --coverage --testr-args=$@ +baseline=`coverage report | tail -1 | tr " " "\n" | tail -1` + +# Checkout back to user directory to get current coverage +git checkout - +git stash pop || true + +python setup.py testr --coverage --testr-args=$@ +current=`coverage report | tail -1 | tr " " "\n" | tail -1 ` + +echo "Coverage baseline: ${baseline} current: ${current}" + +# If coverage was reduced by 0.01% job will fail + +code=`python -c "base=float(\"${baseline}\"[:-1]); current=float(\"${current}\"[:-1]); print(base - current > 0.01 and 1 or 0)"` + + +if [ $code -eq 0 ]; +then + echo "Thank you! You are awesome! Keep writing unit tests! :)" +else + echo "Please write more unit tests, we should keep our test coverage :( " +fi + +exit $code diff --git a/tox.ini b/tox.ini index 0d03d172..e544cfa3 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,8 @@ sitepackages = True commands = {toxinidir}/tests/ci/rally-integrated.sh [testenv:cover] -commands = python setup.py testr --coverage --testr-args='{posargs}' +commands = {toxinidir}/tests/ci/cover.sh {posargs} + [testenv:docs] changedir = doc/source