Tox: add a pep8 target
[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_tests() {
26     echo "Get external libs needed for unit test"
27
28     echo "Running unittest ... "
29     if [ $FILE_OPTION == "f" ]; then
30         python -m unittest discover -v -s tests/unit > $logfile 2>&1
31     else
32         python -m unittest discover -v -s tests/unit
33     fi
34
35     if [ $? -ne 0 ]; then
36         if [ $FILE_OPTION == "f" ]; then
37             echo "FAILED, results in $logfile"
38         fi
39         exit 1
40     else
41         if [ $FILE_OPTION == "f" ]; then
42             echo "OK, results in $logfile"
43         fi
44     fi
45 }
46
47 run_coverage() {
48     # don't re-run coverage on both py27 py3, it takes too long
49     if [[ -z $SKIP_COVERAGE ]] ; then
50         source $COVER_DIR_NAME/cover.sh
51         run_coverage_test
52     fi
53 }
54
55 run_functional_test() {
56
57     mkdir -p .testrepository
58     python -m subunit.run discover tests/functional > .testrepository/subunit.log
59
60     subunit2pyunit < .testrepository/subunit.log
61     EXIT_CODE=$?
62     subunit-stats < .testrepository/subunit.log
63
64     if [ $EXIT_CODE -ne 0 ]; then
65         exit 1
66     else
67         echo "OK"
68     fi
69 }
70
71
72 run_tests
73 run_coverage
74 run_functional_test