summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhurong <aaronzhu1121@gmail.com>2018-09-10 11:39:00 +0800
committerzhurong <aaronzhu1121@gmail.com>2018-09-10 11:39:00 +0800
commit2c2d5121241c6d4ce761aa56913ad6263f4377c6 (patch)
tree776eeed9b40670404b69f1578dc4cdefe4640811
parentceeb3a178b47695bc24fc1342fb80df9c86c7525 (diff)
Use standard cover tox envHEADmaster
Notes
Notes (review): Code-Review+2: zhurong <aaronzhu1121@gmail.com> Workflow+1: zhurong <aaronzhu1121@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 10 Sep 2018 04:53:17 +0000 Reviewed-on: https://review.openstack.org/601159 Project: openstack/python-muranoclient Branch: refs/heads/master
-rwxr-xr-xtools/cover.sh87
-rw-r--r--tox.ini9
2 files changed, 8 insertions, 88 deletions
diff --git a/tools/cover.sh b/tools/cover.sh
deleted file mode 100755
index 90cb1fd..0000000
--- a/tools/cover.sh
+++ /dev/null
@@ -1,87 +0,0 @@
1#!/bin/bash
2#
3# Copyright 2016: 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
19
20show_diff () {
21 head -1 $1
22 diff -U 0 $1 $2 | sed 1,2d
23}
24
25# Stash uncommitted changes, checkout master and save coverage report
26uncommitted=$(git status --porcelain | grep -v "^??")
27[[ -n $uncommitted ]] && git stash > /dev/null
28git checkout HEAD^
29
30baseline_report=$(mktemp -t muranoclient_coverageXXXXXXX)
31find . -type f -name "*.pyc" -delete
32stestr run '{posargs}'
33coverage combine
34coverage html -d cover
35coverage xml -o cover/coverage.xml
36coverage report > $baseline_report
37baseline_missing=$(awk 'END { print $3 }' $baseline_report)
38
39# Checkout back and unstash uncommitted changes (if any)
40git checkout -
41[[ -n $uncommitted ]] && git stash pop > /dev/null
42
43# Generate and save coverage report
44current_report=$(mktemp -t muranoclient_coverageXXXXXXX)
45find . -type f -name "*.pyc" -delete
46stestr run '{posargs}'
47coverage combine
48coverage html -d cover
49coverage xml -o cover/coverage.xml
50coverage report > $current_report
51current_missing=$(awk 'END { print $3 }' $current_report)
52
53baseline_percentage=$(awk 'END { print $4 }' $baseline_report)
54current_percentage=$(awk 'END { print $4 }' $current_report)
55# Show coverage details
56allowed_missing=$((baseline_missing+ALLOWED_EXTRA_MISSING))
57
58echo "Baseline report:"
59echo "$(cat ${baseline_report})"
60echo "Proposed change report:"
61echo "$(cat ${current_report})"
62echo ""
63echo ""
64echo "Allowed to introduce missing lines : ${ALLOWED_EXTRA_MISSING}"
65echo "Missing lines in master : ${baseline_missing}"
66echo "Missing lines in proposed change : ${current_missing}"
67echo "Current percentage : ${baseline_percentage}"
68echo "Proposed change percentage : ${current_percentage}"
69
70if [ $allowed_missing -gt $current_missing ];
71then
72 if [ $baseline_missing -lt $current_missing ];
73 then
74 show_diff $baseline_report $current_report
75 echo "I believe you can cover all your code with 100% coverage!"
76 else
77 echo "Thank you! You are awesome! Keep writing unit tests! :)"
78 fi
79 exit_code=0
80else
81 show_diff $baseline_report $current_report
82 echo "Please write more unit tests, we should keep our test coverage :( "
83 exit_code=1
84fi
85
86rm $baseline_report $current_report
87exit $exit_code
diff --git a/tox.ini b/tox.ini
index 6add8ba..c4b8f15 100644
--- a/tox.ini
+++ b/tox.ini
@@ -40,7 +40,14 @@ commands = stestr run --slowest --concurrency 1 {posargs}
40 40
41[testenv:cover] 41[testenv:cover]
42basepython = python3 42basepython = python3
43commands = {toxinidir}/tools/cover.sh {posargs} 43setenv =
44 {[testenv]setenv}
45 PYTHON=coverage run --source muranoclient --parallel-mode
46commands =
47 stestr run {posargs}
48 coverage combine
49 coverage html -d cover
50 coverage xml -o cover/coverage.xml
44 51
45[testenv:debug] 52[testenv:debug]
46basepython = python3 53basepython = python3