Browse Source

updating run_tests.sh to mimic other openstack projects, pep8, pylint, coverage

tags/2011.3
Joe Heck 8 years ago
parent
commit
6d633a9ec7
5 changed files with 196 additions and 22 deletions
  1. 3
    1
      .gitignore
  2. 42
    0
      .pylintrc
  3. 6
    5
      django-openstack/buildout.cfg
  4. 1
    0
      openstack-dashboard/tools/pip-requires
  5. 144
    16
      run_tests.sh

+ 3
- 1
.gitignore View File

@@ -1,6 +1,8 @@
*.pyc
*.swp
django-openstack/.coverage
.coverage
coverage.xml
reports
django-openstack/.installed.cfg
django-openstack/bin
django-openstack/develop-eggs/

+ 42
- 0
.pylintrc View File

@@ -0,0 +1,42 @@
# The format of this file isn't really documented; just use --generate-rcfile
[MASTER]
# Add <file or directory> to the black list. It should be a base name, not a
# path. You may set this option multiple times.
ignore=test

[Messages Control]
# NOTE(justinsb): We might want to have a 2nd strict pylintrc in future
# C0111: Don't require docstrings on every method
# W0511: TODOs in code comments are fine.
# W0142: *args and **kwargs are fine.
# W0622: Redefining id is fine.
disable=C0111,W0511,W0142,W0622

[Basic]
# Variable names can be 1 to 31 characters long, with lowercase and underscores
variable-rgx=[a-z_][a-z0-9_]{0,30}$

# Argument names can be 2 to 31 characters long, with lowercase and underscores
argument-rgx=[a-z_][a-z0-9_]{1,30}$

# Method names should be at least 3 characters long
# and be lowecased with underscores
method-rgx=([a-z_][a-z0-9_]{2,50}|setUp|tearDown)$

# Module names matching keystone-* are ok (files in bin/)
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(keystone-[a-z0-9_-]+))$

# Don't require docstrings on tests.
no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$

[Design]
max-public-methods=100
min-public-methods=0
max-args=6

[Variables]

# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
# _ is used by our localization
additional-builtins=_

+ 6
- 5
django-openstack/buildout.cfg View File

@@ -1,5 +1,5 @@
[buildout]
parts =
parts =
django
launchpad
openstack-compute
@@ -23,10 +23,11 @@ webob = 1.0.8
# dependencies that are found locally ${buildout:directory}/module
# or can be fetched from pypi
recipe = zc.recipe.egg
eggs =
eggs =
django-mailer
httplib2
python-cloudfiles
coverage
interpreter = python


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


## Dependencies fetch from other bzr locations
#[bzrdeps]
#recipe = bazaarrecipe
#urls =
#urls =
# https://launchpad.net/~hudson-openstack/glance/trunk/ glance

+ 1
- 0
openstack-dashboard/tools/pip-requires View File

@@ -15,6 +15,7 @@ PasteDeploy
sqlalchemy-migrate
eventlet
xattr
coverage

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

+ 144
- 16
run_tests.sh View File

@@ -1,18 +1,146 @@
#!/bin/bash

cd django-openstack
python bootstrap.py
bin/buildout
bin/test
# get results of the django-openstack tests
OPENSTACK_RESULT=$?

cd ../openstack-dashboard
python tools/install_venv.py

cp local/local_settings.py.example local/local_settings.py
tools/with_venv.sh dashboard/manage.py test
# get results of the openstack-dashboard tests
DASHBOARD_RESULT=$?

exit $(($OPENSTACK_RESULT || $DASHBOARD_RESULT))
function usage {
echo "Usage: $0 [OPTION]..."
echo "Run Maestro's test suite(s)"
echo ""
echo " -V, --virtual-env Always use virtualenv. Install automatically"
echo " if not present"
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local"
echo " environment"
echo " -f, --force Force a clean re-build of the virtual"
echo " environment. Useful when dependencies have"
echo " been added."
echo " -p, --pep8 Just run pep8"
echo " -y, --pylint Just run pylint"
echo " -h, --help Print this usage message"
echo ""
echo "Note: with no options specified, the script will try to run the tests in"
echo " a virtual environment, If no virtualenv is found, the script will ask"
echo " if you would like to create one. If you prefer to run tests NOT in a"
echo " virtual environment, simply pass the -N option."
exit
}

function process_option {
case "$1" in
-h|--help) usage;;
-V|--virtual-env) let always_venv=1; let never_venv=0;;
-N|--no-virtual-env) let always_venv=0; let never_venv=1;;
-p|--pep8) let just_pep8=1;;
-y|--pylint) let just_pylint=1;;
-f|--force) let force=1;;
*) testargs="$testargs $1"
esac
}

function run_pylint {
echo "Running pylint ..."
PYLINT_INCLUDE="openstack-dashboard/dashboard django-openstack/django_openstack"
${wrapper} pylint --rcfile=.pylintrc -f parseable $PYLINT_INCLUDE > pylint.txt
CODE=$?
grep Global -A2 pylint.txt
if [ $CODE -lt 32 ]
then
exit 0
else
exit $CODE
fi
}

function run_pep8 {
echo "Running pep8 ..."
PEP8_EXCLUDE=vcsversion.py
PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-pep8 --show-source"
PEP8_INCLUDE="openstack-dashboard/dashboard django-openstack/django_openstack"
${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt
#perl string strips out the [ and ] characters
#${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE | perl -ple 's/: ([WE]\d+)/: [$1]/' > pep8.txt
}


# DEFAULTS FOR RUN_TESTS.SH
#
venv=openstack-dashboard/.dashboard-venv
django_with_venv=openstack-dashboard/tools/with_venv.sh
dashboard_with_venv=tools/with_venv.sh
always_venv=0
never_venv=0
force=0
testargs=""
django_wrapper=""
dashboard_wrapper=""
just_pep8=0
just_pylint=0

# PROCESS ARGUMENTS, OVERRIDE DEFAULTS
for arg in "$@"; do
process_option $arg
done

if [ $never_venv -eq 0 ]
then
# Remove the virtual environment if --force used
if [ $force -eq 1 ]; then
echo "Cleaning virtualenv..."
rm -rf ${venv}
fi
if [ -e ${venv} ]; then
django_wrapper="${django_with_venv}"
dashboard_wrapper="${dashboard_with_venv}"
else
if [ $always_venv -eq 1 ]; then
# Automatically install the virtualenv
python tools/install_venv.py
django_wrapper="${django_with_venv}"
dashboard_wrapper="${dashboard_with_venv}"
else
echo -e "No virtual environment found...create one? (Y/n) \c"
read use_ve
if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
# Install the virtualenv and run the test suite in it
python tools/install_venv.py
django_wrapper="${django_with_venv}"
dashboard_wrapper="${dashboard_with_venv}"
fi
fi
fi
fi

function run_tests {
echo "Running django-openstack (core django) tests"
${django_wrapper} coverage erase
cd django-openstack
python bootstrap.py
bin/buildout
cd ..
${django_wrapper} coverage run django-openstack/bin/test
# get results of the django-openstack tests
OPENSTACK_RESULT=$?

echo "Running openstack-dashboard (django website) tests"
cd openstack-dashboard
cp local/local_settings.py.example local/local_settings.py
${dashboard_wrapper} coverage run dashboard/manage.py test
# get results of the openstack-dashboard tests
DASHBOARD_RESULT=$?
cd ..

echo "Generating coverage reports"
${django_wrapper} coverage combine
${django_wrapper} coverage xml --omit='/usr*,setup.py,*egg*'
${django_wrapper} coverage html --omit='/usr*,setup.py,*egg*' -d reports
exit $(($OPENSTACK_RESULT || $DASHBOARD_RESULT))
}

if [ $just_pep8 -eq 1 ]; then
run_pep8
exit $?
fi

if [ $just_pylint -eq 1 ]; then
run_pylint
exit $?
fi

run_tests || exit

Loading…
Cancel
Save