~ubuntu-branches/ubuntu/saucy/python-cinderclient/saucy-proposed

« back to all changes in this revision

Viewing changes to run_tests.sh

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-06-27 13:32:14 UTC
  • Revision ID: package-import@ubuntu.com-20120627133214-n2gx1yxu97efvhg8
Tags: upstream-2012.2~f1~20120621.8
ImportĀ upstreamĀ versionĀ 2012.2~f1~20120621.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
set -eu
 
4
 
 
5
function usage {
 
6
  echo "Usage: $0 [OPTION]..."
 
7
  echo "Run python-cinderclient test suite"
 
8
  echo ""
 
9
  echo "  -V, --virtual-env        Always use virtualenv.  Install automatically if not present"
 
10
  echo "  -N, --no-virtual-env     Don't use virtualenv.  Run tests in local environment"
 
11
  echo "  -s, --no-site-packages   Isolate the virtualenv from the global Python environment"
 
12
  echo "  -x, --stop               Stop running tests after the first error or failure."
 
13
  echo "  -f, --force              Force a clean re-build of the virtual environment. Useful when dependencies have been added."
 
14
  echo "  -p, --pep8               Just run pep8"
 
15
  echo "  -P, --no-pep8            Don't run pep8"
 
16
  echo "  -c, --coverage           Generate coverage report"
 
17
  echo "  -h, --help               Print this usage message"
 
18
  echo "  --hide-elapsed           Don't print the elapsed time for each test along with slow test list"
 
19
  echo ""
 
20
  echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
 
21
  echo "      If no virtualenv is found, the script will ask if you would like to create one.  If you "
 
22
  echo "      prefer to run tests NOT in a virtual environment, simply pass the -N option."
 
23
  exit
 
24
}
 
25
 
 
26
function process_option {
 
27
  case "$1" in
 
28
    -h|--help) usage;;
 
29
    -V|--virtual-env) always_venv=1; never_venv=0;;
 
30
    -N|--no-virtual-env) always_venv=0; never_venv=1;;
 
31
    -s|--no-site-packages) no_site_packages=1;;
 
32
    -f|--force) force=1;;
 
33
    -p|--pep8) just_pep8=1;;
 
34
    -P|--no-pep8) no_pep8=1;;
 
35
    -c|--coverage) coverage=1;;
 
36
    -*) noseopts="$noseopts $1";;
 
37
    *) noseargs="$noseargs $1"
 
38
  esac
 
39
}
 
40
 
 
41
venv=.venv
 
42
with_venv=tools/with_venv.sh
 
43
always_venv=0
 
44
never_venv=0
 
45
force=0
 
46
no_site_packages=0
 
47
installvenvopts=
 
48
noseargs=
 
49
noseopts=
 
50
wrapper=""
 
51
just_pep8=0
 
52
no_pep8=0
 
53
coverage=0
 
54
 
 
55
for arg in "$@"; do
 
56
  process_option $arg
 
57
done
 
58
 
 
59
# If enabled, tell nose to collect coverage data
 
60
if [ $coverage -eq 1 ]; then
 
61
    noseopts="$noseopts --with-coverage --cover-package=cinderclient"
 
62
fi
 
63
 
 
64
if [ $no_site_packages -eq 1 ]; then
 
65
  installvenvopts="--no-site-packages"
 
66
fi
 
67
 
 
68
function run_tests {
 
69
  # Cleanup *.pyc
 
70
  ${wrapper} find . -type f -name "*.pyc" -delete
 
71
  # Just run the test suites in current environment
 
72
  ${wrapper} $NOSETESTS
 
73
  # If we get some short import error right away, print the error log directly
 
74
  RESULT=$?
 
75
  return $RESULT
 
76
}
 
77
 
 
78
function run_pep8 {
 
79
  echo "Running pep8 ..."
 
80
  srcfiles="cinderclient tests"
 
81
  # Just run PEP8 in current environment
 
82
  #
 
83
  # NOTE(sirp): W602 (deprecated 3-arg raise) is being ignored for the
 
84
  # following reasons:
 
85
  #
 
86
  #  1. It's needed to preserve traceback information when re-raising
 
87
  #     exceptions; this is needed b/c Eventlet will clear exceptions when
 
88
  #     switching contexts.
 
89
  #
 
90
  #  2. There doesn't appear to be an alternative, "pep8-tool" compatible way of doing this
 
91
  #     in Python 2 (in Python 3 `with_traceback` could be used).
 
92
  #
 
93
  #  3. Can find no corroborating evidence that this is deprecated in Python 2
 
94
  #     other than what the PEP8 tool claims. It is deprecated in Python 3, so,
 
95
  #     perhaps the mistake was thinking that the deprecation applied to Python 2
 
96
  #     as well.
 
97
  pep8_opts="--ignore=E202,W602 --repeat"
 
98
  ${wrapper} pep8 ${pep8_opts} ${srcfiles}
 
99
}
 
100
 
 
101
NOSETESTS="nosetests $noseopts $noseargs"
 
102
 
 
103
if [ $never_venv -eq 0 ]
 
104
then
 
105
  # Remove the virtual environment if --force used
 
106
  if [ $force -eq 1 ]; then
 
107
    echo "Cleaning virtualenv..."
 
108
    rm -rf ${venv}
 
109
  fi
 
110
  if [ -e ${venv} ]; then
 
111
    wrapper="${with_venv}"
 
112
  else
 
113
    if [ $always_venv -eq 1 ]; then
 
114
      # Automatically install the virtualenv
 
115
      python tools/install_venv.py $installvenvopts
 
116
      wrapper="${with_venv}"
 
117
    else
 
118
      echo -e "No virtual environment found...create one? (Y/n) \c"
 
119
      read use_ve
 
120
      if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
 
121
        # Install the virtualenv and run the test suite in it
 
122
        python tools/install_venv.py $installvenvopts
 
123
        wrapper=${with_venv}
 
124
      fi
 
125
    fi
 
126
  fi
 
127
fi
 
128
 
 
129
# Delete old coverage data from previous runs
 
130
if [ $coverage -eq 1 ]; then
 
131
    ${wrapper} coverage erase
 
132
fi
 
133
 
 
134
if [ $just_pep8 -eq 1 ]; then
 
135
    run_pep8
 
136
    exit
 
137
fi
 
138
 
 
139
run_tests
 
140
 
 
141
# NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
 
142
# not when we're running tests individually. To handle this, we need to
 
143
# distinguish between options (noseopts), which begin with a '-', and
 
144
# arguments (noseargs).
 
145
if [ -z "$noseargs" ]; then
 
146
  if [ $no_pep8 -eq 0 ]; then
 
147
    run_pep8
 
148
  fi
 
149
fi
 
150
 
 
151
if [ $coverage -eq 1 ]; then
 
152
    echo "Generating coverage report in covhtml/"
 
153
    ${wrapper} coverage html -d covhtml -i
 
154
fi