Browse Source

Use standard cover tox env

Change-Id: Ia561aa9aa7a8c812594651c1d82fd6d8844068a8
zhurong 7 months ago
parent
commit
7204695b69
2 changed files with 8 additions and 78 deletions
  1. 0
    77
      tools/cover.sh
  2. 8
    1
      tox.ini

+ 0
- 77
tools/cover.sh View File

@@ -1,77 +0,0 @@
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
-
18
-ALLOWED_EXTRA_MISSING=4
19
-
20
-show_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
26
-uncommitted=$(git status --porcelain | grep -v "^??")
27
-[[ -n $uncommitted ]] && git stash > /dev/null
28
-git checkout HEAD^
29
-
30
-baseline_report=$(mktemp -t murano_coverageXXXXXXX)
31
-find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*"
32
-coverage report > $baseline_report
33
-baseline_missing=$(awk 'END { print $3 }' $baseline_report)
34
-
35
-# Checkout back and unstash uncommitted changes (if any)
36
-git checkout -
37
-[[ -n $uncommitted ]] && git stash pop > /dev/null
38
-
39
-# Generate and save coverage report
40
-current_report=$(mktemp -t murano_coverageXXXXXXX)
41
-find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*"
42
-coverage report > $current_report
43
-current_missing=$(awk 'END { print $3 }' $current_report)
44
-
45
-baseline_percentage=$(awk 'END { print $6 }' $baseline_report)
46
-current_percentage=$(awk 'END { print $6 }' $current_report)
47
-# Show coverage details
48
-allowed_missing=$((baseline_missing+ALLOWED_EXTRA_MISSING))
49
-
50
-echo "Baseline report: $(cat ${baseline_report})"
51
-echo "Proposed change report: $(cat ${current_report})"
52
-echo ""
53
-echo ""
54
-echo "Allowed to introduce missing lines : ${ALLOWED_EXTRA_MISSING}"
55
-echo "Missing lines in master            : ${baseline_missing}"
56
-echo "Missing lines in proposed change   : ${current_missing}"
57
-echo "Current percentage                 : ${baseline_percentage}"
58
-echo "Proposed change percentage         : ${current_percentage}"
59
-
60
-if [[ $allowed_missing -gt $current_missing ]];
61
-then
62
-    if [[ $baseline_missing -lt $current_missing ]];
63
-    then
64
-        show_diff $baseline_report $current_report
65
-        echo "I believe you can cover all your code with 100% coverage!"
66
-    else
67
-        echo "Thank you! You are awesome! Keep writing unit tests! :)"
68
-    fi
69
-    exit_code=0
70
-else
71
-    show_diff $baseline_report $current_report
72
-    echo "Please write more unit tests, we should keep our test coverage :( "
73
-    exit_code=1
74
-fi
75
-
76
-rm $baseline_report $current_report
77
-exit $exit_code

+ 8
- 1
tox.ini View File

@@ -26,7 +26,14 @@ commands = {posargs}
26 26
 
27 27
 [testenv:cover]
28 28
 basepython = python3
29
-commands = {toxinidir}/tools/cover.sh {posargs}
29
+setenv =
30
+    {[testenv]setenv}
31
+    PYTHON=coverage run --source muranopkgcheck --parallel-mode
32
+commands =
33
+    stestr run {posargs}
34
+    coverage combine
35
+    coverage html -d cover
36
+    coverage xml -o cover/coverage.xml
30 37
 
31 38
 [testenv:docs]
32 39
 basepython = python3

Loading…
Cancel
Save