Skip to content

Commit c1ea298

Browse files
committed
Clean up test environment and remove unused imports.
First round of adding more complete unit test coverage. Change-Id: Ic1979c499ca6fcb784892a95954a3527539c4e53
1 parent 089f4cf commit c1ea298

15 files changed

Lines changed: 377 additions & 57 deletions

File tree

.mailmap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<josh.kearney@pistoncloud.com> <josh@jk0.org>
2+
<matt.joyce@cloudscaling.com> <matt@nycresistor.com>

README.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Additional command-line options and their associated environment variables
9898
are listed here::
9999

100100
--debug # turns on some debugging of the API conversation
101-
(via httplib2)
102101
--verbose | -v # Increase verbosity of output. Can be repeated.
103102
--quiet | -q # suppress output except warnings and errors
104103
--help | -h # show a help message and exit

openstackclient/common/clientmanager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import logging
2222

23-
from openstackclient.common import exceptions as exc
2423
from openstackclient.compute import client as compute_client
2524
from openstackclient.identity import client as identity_client
2625
from openstackclient.image import client as image_client

openstackclient/common/openstackkeyring.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
from Crypto.Cipher import AES
2323

24-
import crypt
2524
import keyring
2625
import os
2726

openstackclient/common/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import sys
2424
import uuid
2525

26-
import prettytable
27-
2826
from openstackclient.common import exceptions
2927

3028

openstackclient/compute/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import logging
1919

20-
from openstackclient.common import exceptions as exc
2120
from openstackclient.common import utils
2221

2322
LOG = logging.getLogger(__name__)

openstackclient/compute/v2/server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import logging
2323
import os
24-
import sys
2524
import time
2625

2726
from cliff import command

openstackclient/identity/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import logging
1919

20-
from openstackclient.common import exceptions as exc
2120
from openstackclient.common import utils
2221

2322
LOG = logging.getLogger(__name__)

openstackclient/openstack/common/setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ def parse_requirements(requirements_files=['requirements.txt',
7878
# -f lines are for index locations, and don't get used here
7979
elif re.match(r'\s*-f\s+', line):
8080
pass
81-
# argparse is part of the standard library starting with 2.7
82-
# adding it to the requirements list screws distro installs
83-
elif line == 'argparse' and sys.version_info >= (2, 7):
84-
pass
8581
else:
8682
requirements.append(line)
8783

run_tests.sh

Lines changed: 125 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,152 @@
11
#!/bin/bash
22

3+
set -eu
4+
35
function usage {
46
echo "Usage: $0 [OPTION]..."
5-
echo "Run python-openstackclient's test suite(s)"
7+
echo "Run python-openstackclient test suite"
68
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."
714
echo " -p, --pep8 Just run pep8"
15+
echo " -P, --no-pep8 Don't run pep8"
16+
echo " -c, --coverage Generate coverage report"
817
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"
919
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".'
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."
1423
exit
1524
}
1625

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-
2626
function process_option {
2727
case "$1" in
2828
-h|--help) usage;;
29-
-p|--pep8) let just_pep8=1;;
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"
3038
esac
3139
}
3240

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+
3355
for arg in "$@"; do
3456
process_option $arg
3557
done
3658

59+
# If enabled, tell nose to collect coverage data
60+
if [ $coverage -eq 1 ]; then
61+
noseopts="$noseopts --with-coverage --cover-package=openstackclient"
62+
fi
63+
64+
if [ $no_site_packages -eq 1 ]; then
65+
installvenvopts="--no-site-packages"
66+
fi
67+
68+
function run_tests {
69+
# Just run the test suites in current environment
70+
${wrapper} $NOSETESTS
71+
# If we get some short import error right away, print the error log directly
72+
RESULT=$?
73+
return $RESULT
74+
}
75+
76+
function run_pep8 {
77+
echo "Running pep8 ..."
78+
srcfiles="openstackclient tests"
79+
# Just run PEP8 in current environment
80+
#
81+
# NOTE(sirp): W602 (deprecated 3-arg raise) is being ignored for the
82+
# following reasons:
83+
#
84+
# 1. It's needed to preserve traceback information when re-raising
85+
# exceptions; this is needed b/c Eventlet will clear exceptions when
86+
# switching contexts.
87+
#
88+
# 2. There doesn't appear to be an alternative, "pep8-tool" compatible way of doing this
89+
# in Python 2 (in Python 3 `with_traceback` could be used).
90+
#
91+
# 3. Can find no corroborating evidence that this is deprecated in Python 2
92+
# other than what the PEP8 tool claims. It is deprecated in Python 3, so,
93+
# perhaps the mistake was thinking that the deprecation applied to Python 2
94+
# as well.
95+
pep8_opts="--ignore=E202,W602 --repeat"
96+
${wrapper} pep8 ${pep8_opts} ${srcfiles}
97+
}
98+
99+
NOSETESTS="nosetests $noseopts $noseargs"
100+
101+
if [ $never_venv -eq 0 ]
102+
then
103+
# Remove the virtual environment if --force used
104+
if [ $force -eq 1 ]; then
105+
echo "Cleaning virtualenv..."
106+
rm -rf ${venv}
107+
fi
108+
if [ -e ${venv} ]; then
109+
wrapper="${with_venv}"
110+
else
111+
if [ $always_venv -eq 1 ]; then
112+
# Automatically install the virtualenv
113+
python tools/install_venv.py $installvenvopts
114+
wrapper="${with_venv}"
115+
else
116+
echo -e "No virtual environment found...create one? (Y/n) \c"
117+
read use_ve
118+
if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
119+
# Install the virtualenv and run the test suite in it
120+
python tools/install_venv.py $installvenvopts
121+
wrapper=${with_venv}
122+
fi
123+
fi
124+
fi
125+
fi
126+
127+
# Delete old coverage data from previous runs
128+
if [ $coverage -eq 1 ]; then
129+
${wrapper} coverage erase
130+
fi
131+
37132
if [ $just_pep8 -eq 1 ]; then
38-
tox -e pep8
39-
exit
133+
run_pep8
134+
exit
40135
fi
41136

42-
tox -e py27 $toxargs 2>&1 | tee run_tests.err.log || exit
43-
if [ ${PIPESTATUS[0]} -ne 0 ]; then
44-
exit ${PIPESTATUS[0]}
137+
run_tests
138+
139+
# NOTE(sirp): we only want to run pep8 when we're running the full-test suite,
140+
# not when we're running tests individually. To handle this, we need to
141+
# distinguish between options (noseopts), which begin with a '-', and
142+
# arguments (noseargs).
143+
if [ -z "$noseargs" ]; then
144+
if [ $no_pep8 -eq 0 ]; then
145+
run_pep8
146+
fi
45147
fi
46148

47-
if [ -z "$toxargs" ]; then
48-
tox -e pep8
149+
if [ $coverage -eq 1 ]; then
150+
echo "Generating coverage report in covhtml/"
151+
${wrapper} coverage html -d covhtml -i
49152
fi

0 commit comments

Comments
 (0)