|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -set -eu |
4 | | - |
5 | 3 | function usage { |
6 | 4 | echo "Usage: $0 [OPTION]..." |
7 | | - echo "Run python-openstackclient test suite" |
| 5 | + echo "Run python-openstackclient's test suite(s)" |
8 | 6 | 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 " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added." |
13 | 7 | echo " -p, --pep8 Just run pep8" |
14 | | - echo " -P, --no-pep8 Don't run pep8" |
15 | | - echo " -c, --coverage Generate coverage report" |
16 | 8 | echo " -h, --help Print this usage message" |
17 | 9 | echo "" |
18 | | - echo "Note: with no options specified, the script will try to run the tests in a virtual environment," |
19 | | - echo " If no virtualenv is found, the script will ask if you would like to create one. If you " |
20 | | - echo " prefer to run tests NOT in a virtual environment, simply pass the -N option." |
| 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".' |
21 | 14 | exit |
22 | 15 | } |
23 | 16 |
|
| 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 | + |
24 | 26 | function process_option { |
25 | 27 | case "$1" in |
26 | 28 | -h|--help) usage;; |
27 | | - -V|--virtual-env) always_venv=1; never_venv=0;; |
28 | | - -N|--no-virtual-env) always_venv=0; never_venv=1;; |
29 | | - -s|--no-site-packages) no_site_packages=1;; |
30 | | - -f|--force) force=1;; |
31 | | - -p|--pep8) just_pep8=1;; |
32 | | - -P|--no-pep8) no_pep8=1;; |
33 | | - -c|--coverage) coverage=1;; |
34 | | - -*) testropts="$testropts $1";; |
35 | | - *) testrargs="$testrargs $1" |
| 29 | + -p|--pep8) let just_pep8=1;; |
36 | 30 | esac |
37 | 31 | } |
38 | 32 |
|
39 | | -venv=.venv |
40 | | -with_venv=tools/with_venv.sh |
41 | | -always_venv=0 |
42 | | -never_venv=0 |
43 | | -force=0 |
44 | | -no_site_packages=0 |
45 | | -installvenvopts= |
46 | | -testrargs= |
47 | | -testropts= |
48 | | -wrapper="" |
49 | | -just_pep8=0 |
50 | | -no_pep8=0 |
51 | | -coverage=0 |
52 | | - |
53 | | -LANG=en_US.UTF-8 |
54 | | -LANGUAGE=en_US:en |
55 | | -LC_ALL=C |
56 | | - |
57 | 33 | for arg in "$@"; do |
58 | 34 | process_option $arg |
59 | 35 | done |
60 | 36 |
|
61 | | -if [ $no_site_packages -eq 1 ]; then |
62 | | - installvenvopts="--no-site-packages" |
63 | | -fi |
64 | | - |
65 | | -function init_testr { |
66 | | - if [ ! -d .testrepository ]; then |
67 | | - ${wrapper} testr init |
68 | | - fi |
69 | | -} |
70 | | - |
71 | | -function run_tests { |
72 | | - # Cleanup *.pyc |
73 | | - ${wrapper} find . -type f -name "*.pyc" -delete |
74 | | - |
75 | | - if [ $coverage -eq 1 ]; then |
76 | | - # Do not test test_coverage_ext when gathering coverage. |
77 | | - if [ "x$testrargs" = "x" ]; then |
78 | | - testrargs="^(?!.*test_coverage_ext).*$" |
79 | | - fi |
80 | | - export PYTHON="${wrapper} coverage run --source openstackclient --parallel-mode" |
81 | | - fi |
82 | | - # Just run the test suites in current environment |
83 | | - set +e |
84 | | - TESTRTESTS="$TESTRTESTS $testrargs" |
85 | | - echo "Running \`${wrapper} $TESTRTESTS\`" |
86 | | - ${wrapper} $TESTRTESTS |
87 | | - RESULT=$? |
88 | | - set -e |
89 | | - |
90 | | - copy_subunit_log |
91 | | - |
92 | | - return $RESULT |
93 | | -} |
94 | | - |
95 | | -function copy_subunit_log { |
96 | | - LOGNAME=`cat .testrepository/next-stream` |
97 | | - LOGNAME=$(($LOGNAME - 1)) |
98 | | - LOGNAME=".testrepository/${LOGNAME}" |
99 | | - cp $LOGNAME subunit.log |
100 | | -} |
101 | | - |
102 | | -function run_pep8 { |
103 | | - echo "Running pep8 ..." |
104 | | - srcfiles="openstackclient tests setup.py" |
105 | | - # Just run PEP8 in current environment |
106 | | - # |
107 | | - # NOTE(sirp): W602 (deprecated 3-arg raise) is being ignored for the |
108 | | - # following reasons: |
109 | | - # |
110 | | - # 1. It's needed to preserve traceback information when re-raising |
111 | | - # exceptions; this is needed b/c Eventlet will clear exceptions when |
112 | | - # switching contexts. |
113 | | - # |
114 | | - # 2. There doesn't appear to be an alternative, "pep8-tool" compatible way of doing this |
115 | | - # in Python 2 (in Python 3 `with_traceback` could be used). |
116 | | - # |
117 | | - # 3. Can find no corroborating evidence that this is deprecated in Python 2 |
118 | | - # other than what the PEP8 tool claims. It is deprecated in Python 3, so, |
119 | | - # perhaps the mistake was thinking that the deprecation applied to Python 2 |
120 | | - # as well. |
121 | | - pep8_opts="--ignore=E126,E202,W602 --repeat" |
122 | | - ${wrapper} pep8 ${pep8_opts} ${srcfiles} |
123 | | -} |
124 | | - |
125 | | -TESTRTESTS="testr run --parallel $testropts" |
126 | | - |
127 | | -if [ $never_venv -eq 0 ] |
128 | | -then |
129 | | - # Remove the virtual environment if --force used |
130 | | - if [ $force -eq 1 ]; then |
131 | | - echo "Cleaning virtualenv..." |
132 | | - rm -rf ${venv} |
133 | | - fi |
134 | | - if [ -e ${venv} ]; then |
135 | | - wrapper="${with_venv}" |
136 | | - else |
137 | | - if [ $always_venv -eq 1 ]; then |
138 | | - # Automatically install the virtualenv |
139 | | - python tools/install_venv.py $installvenvopts |
140 | | - wrapper="${with_venv}" |
141 | | - else |
142 | | - echo -e "No virtual environment found...create one? (Y/n) \c" |
143 | | - read use_ve |
144 | | - if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
145 | | - # Install the virtualenv and run the test suite in it |
146 | | - python tools/install_venv.py $installvenvopts |
147 | | - wrapper=${with_venv} |
148 | | - fi |
149 | | - fi |
150 | | - fi |
151 | | -fi |
152 | | - |
153 | | -# Delete old coverage data from previous runs |
154 | | -if [ $coverage -eq 1 ]; then |
155 | | - ${wrapper} coverage erase |
156 | | -fi |
157 | | - |
158 | 37 | if [ $just_pep8 -eq 1 ]; then |
159 | | - run_pep8 |
160 | | - exit |
| 38 | + exec tox -e pep8 |
161 | 39 | fi |
162 | 40 |
|
163 | | -init_testr |
164 | | -run_tests |
165 | | - |
166 | | -# NOTE(sirp): we only want to run pep8 when we're running the full-test suite, |
167 | | -# not when we're running tests individually. To handle this, we need to |
168 | | -# distinguish between options (noseopts), which begin with a '-', and |
169 | | -# arguments (testrargs). |
170 | | -if [ -z "$testrargs" ]; then |
171 | | - if [ $no_pep8 -eq 0 ]; then |
172 | | - run_pep8 |
173 | | - fi |
| 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 |
174 | 45 | fi |
175 | 46 |
|
176 | | -if [ $coverage -eq 1 ]; then |
177 | | - echo "Generating coverage report in covhtml/" |
178 | | - ${wrapper} coverage combine |
179 | | - ${wrapper} coverage html --include='openstackclient/*' --omit='openstackclient/openstack/common/*' -d covhtml -i |
| 47 | +if [ -z "$toxargs" ]; then |
| 48 | + tox -e pep8 |
180 | 49 | fi |
0 commit comments