PEP8 fixes in /glance/store/__init__.py

Also makes run_tests.sh automatically call pep8.
Pulls in Nova's run_tests.py wrapper for prettying
up output from nosetests...
This commit is contained in:
jaypipes@gmail.com 2011-01-19 14:22:41 -05:00
parent 56fa9a39bf
commit 96eb80f589
3 changed files with 108 additions and 33 deletions

View File

@ -62,8 +62,7 @@ def get_backend_class(backend):
"http": HTTPBackend,
"https": HTTPBackend,
"swift": SwiftBackend,
"s3": S3Backend
}
"s3": S3Backend}
try:
return BACKENDS[backend]
@ -140,4 +139,3 @@ def parse_uri_tokens(parsed_uri, example_url):
authurl = "https://%s" % '/'.join(path_parts)
return user, key, authurl, container, obj

67
run_tests.py Normal file
View File

@ -0,0 +1,67 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 OpenStack, LLC
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import gettext
import os
import unittest
import sys
from nose import config
from nose import result
from nose import core
class GlanceTestResult(result.TextTestResult):
def __init__(self, *args, **kw):
result.TextTestResult.__init__(self, *args, **kw)
self._last_case = None
def getDescription(self, test):
return str(test)
def startTest(self, test):
unittest.TestResult.startTest(self, test)
current_case = test.test.__class__.__name__
if self.showAll:
if current_case != self._last_case:
self.stream.writeln(current_case)
self._last_case = current_case
self.stream.write(
' %s' % str(test.test._testMethodName).ljust(60))
self.stream.flush()
class GlanceTestRunner(core.TextTestRunner):
def _makeResult(self):
return GlanceTestResult(self.stream,
self.descriptions,
self.verbosity,
self.config)
if __name__ == '__main__':
c = config.Config(stream=sys.stdout,
env=os.environ,
verbosity=3)
runner = GlanceTestRunner(stream=c.stream,
verbosity=c.verbosity,
config=c)
sys.exit(not core.run(config=c, testRunner=runner))

View File

@ -6,6 +6,7 @@ function usage {
echo ""
echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
echo " -h, --help Print this usage message"
echo ""
echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
@ -14,20 +15,13 @@ function usage {
exit
}
function process_options {
array=$1
elements=${#array[@]}
for (( x=0;x<$elements;x++)); do
process_option ${array[${x}]}
done
}
function process_option {
option=$1
case $option in
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;;
-f|--force) let force=1;;
*) noseargs="$noseargs $1"
esac
}
@ -35,32 +29,48 @@ venv=.glance-venv
with_venv=tools/with_venv.sh
always_venv=0
never_venv=0
options=("$@")
force=0
noseargs=
wrapper=""
process_options $options
for arg in "$@"; do
process_option $arg
done
if [ $never_venv -eq 1 ]; then
function run_tests {
# Just run the test suites in current environment
nosetests --logging-clear-handlers
exit
fi
${wrapper} rm -f glance.sqlite
${wrapper} $NOSETESTS 2> run_tests.err.log
}
NOSETESTS="python run_tests.py $noseargs"
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
${with_venv} nosetests --logging-clear-handlers
wrapper="${with_venv}"
else
if [ $always_venv -eq 1 ]; then
# Automatically install the virtualenv
python tools/install_venv.py
wrapper="${with_venv}"
else
echo -e "No virtual environment found...create one? (Y/n) \c"
read use_ve
if [ "x$use_ve" = "xY" ]; then
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
else
nosetests --logging-clear-handlers
exit
wrapper=${with_venv}
fi
fi
${with_venv} nosetests --logging-clear-handlers
fi
fi
run_tests
pep8 --repeat --show-pep8 --show-source bin/* glance setup.py run_tests.py