summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-07-28 21:17:05 +0000
committerGerrit Code Review <review@openstack.org>2015-07-28 21:17:05 +0000
commitc0c073316d77acb33a3a7f931e84cd1aa217d2df (patch)
tree6f13d8cd9bd445066589dc0784f3405a586226a4
parentdb6af81ac2f0a8712baa2a637563098c3624eb4b (diff)
parent4ea9031b4f0a370b033393ef82f6339ec8ec7dae (diff)
Merge "Make coverage tox job fail when test coverage was reduced"1.0.0.0b2
-rw-r--r--.coveragerc8
-rwxr-xr-xtools/cover.sh68
-rw-r--r--tox.ini5
3 files changed, 78 insertions, 3 deletions
diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..b3bf10b
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,8 @@
1[run]
2branch = True
3source = manila
4omit = manila/test*,manila/openstack/*
5
6[report]
7ignore-errors = True
8precision = 2
diff --git a/tools/cover.sh b/tools/cover.sh
new file mode 100755
index 0000000..10f9007
--- /dev/null
+++ b/tools/cover.sh
@@ -0,0 +1,68 @@
1#!/bin/bash
2#
3# Copyright 2015: Mirantis Inc.
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18ALLOWED_EXTRA_MISSING=4
19TESTR_ARGS="$*"
20
21show_diff () {
22 head -1 $1
23 diff -U 0 $1 $2 | sed 1,2d
24}
25
26# Stash uncommited changes, checkout master and save coverage report
27uncommited=$(git status --porcelain | grep -v "^??")
28[[ -n $uncommited ]] && git stash > /dev/null
29git checkout HEAD^
30
31baseline_report=$(mktemp -t manila_coverageXXXXXXX)
32find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$TESTR_ARGS"
33coverage report > $baseline_report
34baseline_missing=$(awk 'END { print $3 }' $baseline_report)
35
36# Checkout back and unstash uncommited changes (if any)
37git checkout -
38[[ -n $uncommited ]] && git stash pop > /dev/null
39
40# Generate and save coverage report
41current_report=$(mktemp -t manila_coverageXXXXXXX)
42find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$TESTR_ARGS"
43coverage report > $current_report
44current_missing=$(awk 'END { print $3 }' $current_report)
45
46# Show coverage details
47allowed_missing=$((baseline_missing+ALLOWED_EXTRA_MISSING))
48
49echo "Allowed to introduce missing lines : ${ALLOWED_EXTRA_MISSING}"
50echo "Missing lines in master : ${baseline_missing}"
51echo "Missing lines in proposed change : ${current_missing}"
52
53if [ $allowed_missing -gt $current_missing ]; then
54 if [ $baseline_missing -lt $current_missing ]; then
55 show_diff $baseline_report $current_report
56 echo "I believe you can cover all your code with 100% coverage!"
57 else
58 echo "Thank you! You are awesome! Keep writing unit tests! :)"
59 fi
60 exit_code=0
61else
62 show_diff $baseline_report $current_report
63 echo "Please write more unit tests, we should keep our test coverage :( "
64 exit_code=1
65fi
66
67rm $baseline_report $current_report
68exit $exit_code
diff --git a/tox.ini b/tox.ini
index 4736a27..c63c1de 100644
--- a/tox.ini
+++ b/tox.ini
@@ -23,6 +23,7 @@ commands =
23 contrib/ci/pre_test_hook.sh \ 23 contrib/ci/pre_test_hook.sh \
24 contrib/ci/post_test_hook.sh \ 24 contrib/ci/post_test_hook.sh \
25 devstack/plugin.sh \ 25 devstack/plugin.sh \
26 tools/cover.sh \
26 run_tests.sh 27 run_tests.sh
27 28
28[testenv:genconfig] 29[testenv:genconfig]
@@ -37,9 +38,7 @@ commands = {posargs}
37commands = python setup.py build_sphinx 38commands = python setup.py build_sphinx
38 39
39[testenv:cover] 40[testenv:cover]
40commands = 41commands = {toxinidir}/tools/cover.sh {posargs}
41 python setup.py testr --coverage \
42 --testr-args='^(?!.*test.*coverage).*$'
43 42
44[testenv:pylint] 43[testenv:pylint]
45deps = -r{toxinidir}/requirements.txt 44deps = -r{toxinidir}/requirements.txt