Skip to content

Commit 6d633a9

Browse files
committed
updating run_tests.sh to mimic other openstack projects, pep8, pylint, coverage
1 parent 0a35900 commit 6d633a9

File tree

5 files changed

+196
-22
lines changed

5 files changed

+196
-22
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*.pyc
22
*.swp
3-
django-openstack/.coverage
3+
.coverage
4+
coverage.xml
5+
reports
46
django-openstack/.installed.cfg
57
django-openstack/bin
68
django-openstack/develop-eggs/

.pylintrc

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# The format of this file isn't really documented; just use --generate-rcfile
2+
[MASTER]
3+
# Add <file or directory> to the black list. It should be a base name, not a
4+
# path. You may set this option multiple times.
5+
ignore=test
6+
7+
[Messages Control]
8+
# NOTE(justinsb): We might want to have a 2nd strict pylintrc in future
9+
# C0111: Don't require docstrings on every method
10+
# W0511: TODOs in code comments are fine.
11+
# W0142: *args and **kwargs are fine.
12+
# W0622: Redefining id is fine.
13+
disable=C0111,W0511,W0142,W0622
14+
15+
[Basic]
16+
# Variable names can be 1 to 31 characters long, with lowercase and underscores
17+
variable-rgx=[a-z_][a-z0-9_]{0,30}$
18+
19+
# Argument names can be 2 to 31 characters long, with lowercase and underscores
20+
argument-rgx=[a-z_][a-z0-9_]{1,30}$
21+
22+
# Method names should be at least 3 characters long
23+
# and be lowecased with underscores
24+
method-rgx=([a-z_][a-z0-9_]{2,50}|setUp|tearDown)$
25+
26+
# Module names matching keystone-* are ok (files in bin/)
27+
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(keystone-[a-z0-9_-]+))$
28+
29+
# Don't require docstrings on tests.
30+
no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$
31+
32+
[Design]
33+
max-public-methods=100
34+
min-public-methods=0
35+
max-args=6
36+
37+
[Variables]
38+
39+
# List of additional names supposed to be defined in builtins. Remember that
40+
# you should avoid to define new builtins when possible.
41+
# _ is used by our localization
42+
additional-builtins=_

django-openstack/buildout.cfg

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[buildout]
2-
parts =
2+
parts =
33
django
44
launchpad
55
openstack-compute
@@ -23,10 +23,11 @@ webob = 1.0.8
2323
# dependencies that are found locally ${buildout:directory}/module
2424
# or can be fetched from pypi
2525
recipe = zc.recipe.egg
26-
eggs =
26+
eggs =
2727
django-mailer
2828
httplib2
2929
python-cloudfiles
30+
coverage
3031
interpreter = python
3132

3233

@@ -93,17 +94,17 @@ as_egg = True
9394
## Dependencies fetched from launchpad
9495
# launchpad dependencies will appear as subfolders of
9596
# ${buildout:directory}/launchpad/
96-
# multiple urls can be specified, format is
97+
# multiple urls can be specified, format is
9798
# branch_url subfolder_name
9899
# don't forget to add directory to extra_paths in [django]
99100
[launchpad]
100101
recipe = bazaarrecipe
101-
urls =
102+
urls =
102103
https://launchpad.net/~hudson-openstack/glance/trunk/ glance
103104

104105

105106
## Dependencies fetch from other bzr locations
106107
#[bzrdeps]
107108
#recipe = bazaarrecipe
108-
#urls =
109+
#urls =
109110
# https://launchpad.net/~hudson-openstack/glance/trunk/ glance

openstack-dashboard/tools/pip-requires

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PasteDeploy
1515
sqlalchemy-migrate
1616
eventlet
1717
xattr
18+
coverage
1819

1920
bzr+https://launchpad.net/glance#egg=glance
2021
bzr+https://launchpad.net/quantum#egg=quantum

run_tests.sh

+144-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,146 @@
11
#!/bin/bash
22

3-
cd django-openstack
4-
python bootstrap.py
5-
bin/buildout
6-
bin/test
7-
# get results of the django-openstack tests
8-
OPENSTACK_RESULT=$?
9-
10-
cd ../openstack-dashboard
11-
python tools/install_venv.py
12-
13-
cp local/local_settings.py.example local/local_settings.py
14-
tools/with_venv.sh dashboard/manage.py test
15-
# get results of the openstack-dashboard tests
16-
DASHBOARD_RESULT=$?
17-
18-
exit $(($OPENSTACK_RESULT || $DASHBOARD_RESULT))
3+
function usage {
4+
echo "Usage: $0 [OPTION]..."
5+
echo "Run Maestro's test suite(s)"
6+
echo ""
7+
echo " -V, --virtual-env Always use virtualenv. Install automatically"
8+
echo " if not present"
9+
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local"
10+
echo " environment"
11+
echo " -f, --force Force a clean re-build of the virtual"
12+
echo " environment. Useful when dependencies have"
13+
echo " been added."
14+
echo " -p, --pep8 Just run pep8"
15+
echo " -y, --pylint Just run pylint"
16+
echo " -h, --help Print this usage message"
17+
echo ""
18+
echo "Note: with no options specified, the script will try to run the tests in"
19+
echo " a virtual environment, If no virtualenv is found, the script will ask"
20+
echo " if you would like to create one. If you prefer to run tests NOT in a"
21+
echo " virtual environment, simply pass the -N option."
22+
exit
23+
}
24+
25+
function process_option {
26+
case "$1" in
27+
-h|--help) usage;;
28+
-V|--virtual-env) let always_venv=1; let never_venv=0;;
29+
-N|--no-virtual-env) let always_venv=0; let never_venv=1;;
30+
-p|--pep8) let just_pep8=1;;
31+
-y|--pylint) let just_pylint=1;;
32+
-f|--force) let force=1;;
33+
*) testargs="$testargs $1"
34+
esac
35+
}
36+
37+
function run_pylint {
38+
echo "Running pylint ..."
39+
PYLINT_INCLUDE="openstack-dashboard/dashboard django-openstack/django_openstack"
40+
${wrapper} pylint --rcfile=.pylintrc -f parseable $PYLINT_INCLUDE > pylint.txt
41+
CODE=$?
42+
grep Global -A2 pylint.txt
43+
if [ $CODE -lt 32 ]
44+
then
45+
exit 0
46+
else
47+
exit $CODE
48+
fi
49+
}
50+
51+
function run_pep8 {
52+
echo "Running pep8 ..."
53+
PEP8_EXCLUDE=vcsversion.py
54+
PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-pep8 --show-source"
55+
PEP8_INCLUDE="openstack-dashboard/dashboard django-openstack/django_openstack"
56+
${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt
57+
#perl string strips out the [ and ] characters
58+
#${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE | perl -ple 's/: ([WE]\d+)/: [$1]/' > pep8.txt
59+
}
60+
61+
62+
# DEFAULTS FOR RUN_TESTS.SH
63+
#
64+
venv=openstack-dashboard/.dashboard-venv
65+
django_with_venv=openstack-dashboard/tools/with_venv.sh
66+
dashboard_with_venv=tools/with_venv.sh
67+
always_venv=0
68+
never_venv=0
69+
force=0
70+
testargs=""
71+
django_wrapper=""
72+
dashboard_wrapper=""
73+
just_pep8=0
74+
just_pylint=0
75+
76+
# PROCESS ARGUMENTS, OVERRIDE DEFAULTS
77+
for arg in "$@"; do
78+
process_option $arg
79+
done
80+
81+
if [ $never_venv -eq 0 ]
82+
then
83+
# Remove the virtual environment if --force used
84+
if [ $force -eq 1 ]; then
85+
echo "Cleaning virtualenv..."
86+
rm -rf ${venv}
87+
fi
88+
if [ -e ${venv} ]; then
89+
django_wrapper="${django_with_venv}"
90+
dashboard_wrapper="${dashboard_with_venv}"
91+
else
92+
if [ $always_venv -eq 1 ]; then
93+
# Automatically install the virtualenv
94+
python tools/install_venv.py
95+
django_wrapper="${django_with_venv}"
96+
dashboard_wrapper="${dashboard_with_venv}"
97+
else
98+
echo -e "No virtual environment found...create one? (Y/n) \c"
99+
read use_ve
100+
if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
101+
# Install the virtualenv and run the test suite in it
102+
python tools/install_venv.py
103+
django_wrapper="${django_with_venv}"
104+
dashboard_wrapper="${dashboard_with_venv}"
105+
fi
106+
fi
107+
fi
108+
fi
109+
110+
function run_tests {
111+
echo "Running django-openstack (core django) tests"
112+
${django_wrapper} coverage erase
113+
cd django-openstack
114+
python bootstrap.py
115+
bin/buildout
116+
cd ..
117+
${django_wrapper} coverage run django-openstack/bin/test
118+
# get results of the django-openstack tests
119+
OPENSTACK_RESULT=$?
120+
121+
echo "Running openstack-dashboard (django website) tests"
122+
cd openstack-dashboard
123+
cp local/local_settings.py.example local/local_settings.py
124+
${dashboard_wrapper} coverage run dashboard/manage.py test
125+
# get results of the openstack-dashboard tests
126+
DASHBOARD_RESULT=$?
127+
cd ..
128+
129+
echo "Generating coverage reports"
130+
${django_wrapper} coverage combine
131+
${django_wrapper} coverage xml --omit='/usr*,setup.py,*egg*'
132+
${django_wrapper} coverage html --omit='/usr*,setup.py,*egg*' -d reports
133+
exit $(($OPENSTACK_RESULT || $DASHBOARD_RESULT))
134+
}
135+
136+
if [ $just_pep8 -eq 1 ]; then
137+
run_pep8
138+
exit $?
139+
fi
140+
141+
if [ $just_pylint -eq 1 ]; then
142+
run_pylint
143+
exit $?
144+
fi
145+
146+
run_tests || exit

0 commit comments

Comments
 (0)