~ubuntu-branches/ubuntu/vivid/python-heatclient/vivid

« back to all changes in this revision

Viewing changes to run_tests.sh

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-03-06 17:41:15 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20140306174115-ecpzxbyb30tl5i7a
Tags: upstream-0.2.8
ImportĀ upstreamĀ versionĀ 0.2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash
2
2
 
 
3
BASE_DIR=`dirname $0`
 
4
 
3
5
function usage {
4
 
  echo "Usage: $0 [OPTION]..."
5
 
  echo "Run python-heatclient's test suite(s)"
6
 
  echo ""
7
 
  echo "  -p, --pep8               Just run pep8"
8
 
  echo "  -h, --help               Print this usage message"
9
 
  echo ""
10
 
  echo "This script is deprecated and currently retained for compatibility."
11
 
  echo 'You can run the full test suite for multiple environments by running "tox".'
12
 
  echo 'You can run tests for only python 2.7 by running "tox -e py27", or run only'
13
 
  echo 'the pep8 tests with "tox -e pep8".'
14
 
  exit
 
6
    echo "Usage: $0 [OPTION]..."
 
7
    echo "Run heatclient test suite(s)"
 
8
    echo ""
 
9
    echo "  -V, --virtual-env        Use virtualenv.  Install automatically if not present."
 
10
    echo "                           (Default is to run tests in local environment)"
 
11
    echo "  -F, --force              Force a clean re-build of the virtual environment. Useful when dependencies have been added."
 
12
    echo "  -f, --func               Functional tests have been removed."
 
13
    echo "  -u, --unit               Run unit tests (default when nothing specified)"
 
14
    echo "  -p, --pep8               Run pep8 tests"
 
15
    echo "  --all                    Run pep8 and unit tests"
 
16
    echo "  -c, --coverage           Generate coverage report"
 
17
    echo "  -d, --debug              Run tests with testtools instead of testr. This allows you to use the debugger."
 
18
    echo "  -h, --help               Print this usage message"
 
19
    exit
15
20
}
16
21
 
17
 
command -v tox > /dev/null 2>&1
18
 
if [ $? -ne 0 ]; then
19
 
  echo 'This script requires "tox" to run.'
20
 
  echo 'You can install it with "pip install tox".'
21
 
  exit 1; 
22
 
fi
23
 
 
24
 
just_pep8=0
25
 
 
 
22
# must not assign -a as an option, needed for selecting custom attributes
 
23
no_venv=1
26
24
function process_option {
27
 
  case "$1" in
28
 
    -h|--help) usage;;
29
 
    -p|--pep8) let just_pep8=1;;
30
 
  esac
31
 
}
32
 
 
33
 
for arg in "$@"; do
34
 
  process_option $arg
35
 
done
36
 
 
37
 
if [ $just_pep8 -eq 1 ]; then
38
 
  exec tox -e pep8
39
 
fi
40
 
 
41
 
tox -e py27 $toxargs 2>&1 | tee run_tests.err.log  || exit 1
42
 
tox_exit_code=${PIPESTATUS[0]}
43
 
if [ 0$tox_exit_code -ne 0 ]; then
44
 
  exit $tox_exit_code
45
 
fi
46
 
 
47
 
if [ -z "$toxargs" ]; then
48
 
  tox -e pep8
49
 
fi
 
25
    case "$1" in
 
26
        -V|--virtual-env) no_venv=0;;
 
27
        -F|--force) force=1;;
 
28
        -f|--func) test_func=1;;
 
29
        -u|--unit) test_unit=1;;
 
30
        -p|--pep8) test_pep8=1;;
 
31
        --all) test_unit=1; test_pep8=1;;
 
32
        -c|--coverage) coverage=1;;
 
33
        -d|--debug) debug=1;;
 
34
        -h|--help) usage;;
 
35
        *) args="$args $1"; test_unit=1;;
 
36
    esac
 
37
}
 
38
 
 
39
venv=.venv
 
40
with_venv=tools/with_venv.sh
 
41
wrapper=""
 
42
debug=0
 
43
 
 
44
function run_tests {
 
45
    echo 'Running tests'
 
46
 
 
47
    if [ $debug -eq 1 ]; then
 
48
      echo "Debugging..."
 
49
      if [ "$args" = "" ]; then
 
50
        # Default to running all tests if specific test is not
 
51
        # provided.
 
52
        testrargs="discover ./heatclient/tests"
 
53
      fi
 
54
      ${wrapper} python -m testtools.run $args $testrargs
 
55
 
 
56
      # Short circuit because all of the testr and coverage stuff
 
57
      # below does not make sense when running testtools.run for
 
58
      # debugging purposes.
 
59
      return $?
 
60
    fi
 
61
 
 
62
    # Just run the test suites in current environment
 
63
    if [ -n "$args" ] ; then
 
64
        args="-t $args"
 
65
    fi
 
66
    ${wrapper} python setup.py testr --slowest $args
 
67
}
 
68
 
 
69
function run_pep8 {
 
70
    echo "Running flake8..."
 
71
    bash -c "${wrapper} flake8"
 
72
}
 
73
 
 
74
# run unit tests with pep8 when no arguments are specified
 
75
# otherwise process CLI options
 
76
if [[ $# == 0 ]]; then
 
77
    test_pep8=1
 
78
    test_unit=1
 
79
else
 
80
    for arg in "$@"; do
 
81
        process_option $arg
 
82
    done
 
83
fi
 
84
 
 
85
if [ "$no_venv" == 0 ]
 
86
then
 
87
    # Remove the virtual environment if --force used
 
88
    if [ "$force" == 1 ]; then
 
89
        echo "Cleaning virtualenv..."
 
90
        rm -rf ${venv}
 
91
    fi
 
92
    if [ -e ${venv} ]; then
 
93
        wrapper="${with_venv}"
 
94
    else
 
95
        # Automatically install the virtualenv
 
96
        python tools/install_venv.py
 
97
        wrapper="${with_venv}"
 
98
    fi
 
99
fi
 
100
 
 
101
result=0
 
102
 
 
103
# If functional or unit tests have been selected, run them
 
104
if [ "$test_unit" == 1 ] || [ "$debug" == 1 ] ; then
 
105
    run_tests
 
106
    result=$?
 
107
fi
 
108
 
 
109
# Run pep8 if it was selected
 
110
if [ "$test_pep8" == 1 ]; then
 
111
    run_pep8
 
112
fi
 
113
 
 
114
# Generate coverage report
 
115
if [ "$coverage" == 1 ]; then
 
116
    echo "Generating coverage report in ./cover"
 
117
    ${wrapper} python setup.py testr --coverage --slowest
 
118
    ${wrapper} python -m coverage report --show-missing
 
119
fi
 
120
 
 
121
exit $result