Browse Source

Use standard cover tox env

Change-Id: I5710cd4d5a8ff95a17e5ef8dae4716fbb333dcf8
zhurong 7 months ago
parent
commit
aa4e9fabc1
3 changed files with 8 additions and 85 deletions
  1. 0
    7
      .testr.conf
  2. 0
    77
      tools/cover.sh
  3. 8
    1
      tox.ini

+ 0
- 7
.testr.conf View File

@@ -1,7 +0,0 @@
1
-[DEFAULT]
2
-test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
3
-             OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
4
-             OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
5
-             ${PYTHON:-python} -m subunit.run discover -t ./ $DISCOVER_DIRECTORY $LISTOPT $IDOPTION
6
-test_id_option=--load-list $IDFILE
7
-test_list_option=--list

+ 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

@@ -42,7 +42,14 @@ commands = {posargs}
42 42
 
43 43
 [testenv:cover]
44 44
 basepython = python3
45
-commands = {toxinidir}/tools/cover.sh {posargs}
45
+setenv =
46
+    {[testenv]setenv}
47
+    PYTHON=coverage run --source murano --parallel-mode
48
+commands =
49
+    stestr run {posargs}
50
+    coverage combine
51
+    coverage html -d cover
52
+    coverage xml -o cover/coverage.xml
46 53
 
47 54
 [testenv:debug]
48 55
 basepython = python3

Loading…
Cancel
Save