From 96eb80f589af94435a91a8bcbab0f0af8cf472c7 Mon Sep 17 00:00:00 2001 From: "jaypipes@gmail.com" <> Date: Wed, 19 Jan 2011 14:22:41 -0500 Subject: [PATCH] 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... --- glance/store/__init__.py | 6 ++-- run_tests.py | 67 +++++++++++++++++++++++++++++++++++++++ run_tests.sh | 68 +++++++++++++++++++++++----------------- 3 files changed, 108 insertions(+), 33 deletions(-) create mode 100644 run_tests.py diff --git a/glance/store/__init__.py b/glance/store/__init__.py index 2955217d8a..820cbb8fa0 100644 --- a/glance/store/__init__.py +++ b/glance/store/__init__.py @@ -62,8 +62,7 @@ def get_backend_class(backend): "http": HTTPBackend, "https": HTTPBackend, "swift": SwiftBackend, - "s3": S3Backend - } + "s3": S3Backend} try: return BACKENDS[backend] @@ -115,7 +114,7 @@ def parse_uri_tokens(parsed_uri, example_url): 1) urlparse to split the tokens 2) use RE to split on @ and / 3) reassemble authurl - + """ path = parsed_uri.path.lstrip('//') netloc = parsed_uri.netloc @@ -140,4 +139,3 @@ def parse_uri_tokens(parsed_uri, example_url): authurl = "https://%s" % '/'.join(path_parts) return user, key, authurl, container, obj - diff --git a/run_tests.py b/run_tests.py new file mode 100644 index 0000000000..8f6531f484 --- /dev/null +++ b/run_tests.py @@ -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)) diff --git a/run_tests.sh b/run_tests.sh index 85911529c7..32deec831d 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -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 +} -if [ -e ${venv} ]; then - ${with_venv} nosetests --logging-clear-handlers -else - if [ $always_venv -eq 1 ]; then - # Automatically install the virtualenv - python tools/install_venv.py +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 + wrapper="${with_venv}" else - echo -e "No virtual environment found...create one? (Y/n) \c" - read use_ve - if [ "x$use_ve" = "xY" ]; then - # Install the virtualenv and run the test suite in it + if [ $always_venv -eq 1 ]; then + # Automatically install the virtualenv python tools/install_venv.py + wrapper="${with_venv}" else - nosetests --logging-clear-handlers - exit + 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 + wrapper=${with_venv} + fi fi fi - ${with_venv} nosetests --logging-clear-handlers fi + +run_tests + +pep8 --repeat --show-pep8 --show-source bin/* glance setup.py run_tests.py