6
echo "Usage: $0 [OPTION]..."
7
echo "Run python-cinderclient test suite"
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"
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."
26
function process_option {
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;;
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"
42
with_venv=tools/with_venv.sh
59
# If enabled, tell nose to collect coverage data
60
if [ $coverage -eq 1 ]; then
61
noseopts="$noseopts --with-coverage --cover-package=cinderclient"
64
if [ $no_site_packages -eq 1 ]; then
65
installvenvopts="--no-site-packages"
70
${wrapper} find . -type f -name "*.pyc" -delete
71
# Just run the test suites in current environment
73
# If we get some short import error right away, print the error log directly
79
echo "Running pep8 ..."
80
srcfiles="cinderclient tests"
81
# Just run PEP8 in current environment
83
# NOTE(sirp): W602 (deprecated 3-arg raise) is being ignored for the
86
# 1. It's needed to preserve traceback information when re-raising
87
# exceptions; this is needed b/c Eventlet will clear exceptions when
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).
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
97
pep8_opts="--ignore=E202,W602 --repeat"
98
${wrapper} pep8 ${pep8_opts} ${srcfiles}
101
NOSETESTS="nosetests $noseopts $noseargs"
103
if [ $never_venv -eq 0 ]
105
# Remove the virtual environment if --force used
106
if [ $force -eq 1 ]; then
107
echo "Cleaning virtualenv..."
110
if [ -e ${venv} ]; then
111
wrapper="${with_venv}"
113
if [ $always_venv -eq 1 ]; then
114
# Automatically install the virtualenv
115
python tools/install_venv.py $installvenvopts
116
wrapper="${with_venv}"
118
echo -e "No virtual environment found...create one? (Y/n) \c"
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
129
# Delete old coverage data from previous runs
130
if [ $coverage -eq 1 ]; then
131
${wrapper} coverage erase
134
if [ $just_pep8 -eq 1 ]; then
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
151
if [ $coverage -eq 1 ]; then
152
echo "Generating coverage report in covhtml/"
153
${wrapper} coverage html -d covhtml -i