Merge "Fix Malformed Table in User Guide docs" into stable/euphrates
[yardstick.git] / run_tests.sh
1 #!/bin/bash
2
3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Run yardstick's flake8, unit, coverage, functional test
13
14 getopts ":f" FILE_OPTION
15
16 # don't write .pyc files this can cause odd unittest results
17 export PYTHONDONTWRITEBYTECODE=1
18
19 PY_VER="py$( python --version | sed 's/[^[:digit:]]//g' | cut -c-2 )"
20 export PY_VER
21
22 COVER_DIR_NAME="./tests/ci/"
23 export COVER_DIR_NAME
24
25 run_flake8() {
26     echo "Running flake8 ... "
27     logfile=test_results.log
28     if [ $FILE_OPTION == "f" ]; then
29         flake8 yardstick > $logfile
30     else
31         flake8 yardstick
32     fi
33
34     if [ $? -ne 0 ]; then
35         echo "FAILED"
36         if [ $FILE_OPTION == "f" ]; then
37             echo "Results in $logfile"
38         fi
39         exit 1
40     else
41         echo "OK"
42     fi
43 }
44
45
46 run_tests() {
47     echo "Get external libs needed for unit test"
48
49     echo "Running unittest ... "
50     if [ $FILE_OPTION == "f" ]; then
51         python -m unittest discover -v -s tests/unit > $logfile 2>&1
52     else
53         python -m unittest discover -v -s tests/unit
54     fi
55
56     if [ $? -ne 0 ]; then
57         if [ $FILE_OPTION == "f" ]; then
58             echo "FAILED, results in $logfile"
59         fi
60         exit 1
61     else
62         if [ $FILE_OPTION == "f" ]; then
63             echo "OK, results in $logfile"
64         fi
65     fi
66 }
67
68 run_coverage() {
69     # don't re-run coverage on both py27 py3, it takes too long
70     if [[ -z $SKIP_COVERAGE ]] ; then
71         source $COVER_DIR_NAME/cover.sh
72         run_coverage_test
73     fi
74 }
75
76 run_functional_test() {
77
78     mkdir -p .testrepository
79     python -m subunit.run discover tests/functional > .testrepository/subunit.log
80
81     subunit2pyunit < .testrepository/subunit.log
82     EXIT_CODE=$?
83     subunit-stats < .testrepository/subunit.log
84
85     if [ $EXIT_CODE -ne 0 ]; then
86         exit 1
87     else
88         echo "OK"
89     fi
90 }
91
92
93 run_flake8
94 run_tests
95 run_coverage
96 run_functional_test