diff --git a/.gitignore b/.gitignore index 355cfbd22..b7451250a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .coverage +.novaclient-venv *,cover cover *.pyc diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 000000000..755f7912c --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,116 @@ +#!/bin/bash +# +# Copyright 2011, Piston Cloud Computing, Inc. +# +# 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. + +function usage { + echo "Usage: $0 [OPTION] [nosearg1[=val]] [nosearg2[=val]]..." + echo + echo "Run python-novaclient test suite" + echo + echo " -f, --force Delete the virtualenv before running tests." + echo " -h, --help Print this usage message" + echo " -N, --no-virtual-env Don't use a virtualenv" + echo " -p, --pep8 Run pep8 in addition" +} + + +function die { + echo $@ + exit 1 +} + + +function process_args { + case "$1" in + -h|--help) usage && exit ;; + -p|--pep8) let just_pep8=1; let use_venv=0 ;; + -N|--no-virtual-env) let use_venv=0;; + -f|--force) let force=1;; + *) noseargs="$noseargs $1" + esac +} + + +function run-command { + res=$($@) + + if [ $? -ne 0 ]; then + die "Command failed:", $res + fi +} + + +function install-dependency { + echo -n "installing $@..." + run-command "pip install -E $venv $@" + echo done +} + + +function build-venv-if-necessary { + if [ $force -eq 1 ]; then + echo -n "Removing virtualenv..." + rm -rf $venv + echo done + fi + + if [ -d $venv ]; then + echo -n # nothing to be done + else + if [ -z $(which virtualenv) ]; then + echo "Installing virtualenv" + run-command "easy_install virtualenv" + fi + + echo -n "creating virtualenv..." + run-command "virtualenv -q --no-site-packages ${venv}" + echo done + + for dep in $dependencies; do + install-dependency $dep + done + fi +} + + +function wrapper { + if [ $use_venv -eq 1 ]; then + build-venv-if-necessary + source "$(dirname $0)/${venv}/bin/activate" && $@ + else + $@ + fi +} + + +dependencies="httplib2 argparse prettytable simplejson nose mock coverage" +force=0 +venv=.novaclient-venv +use_venv=1 +verbose=0 +noseargs= +just_pep8=0 + +for arg in "$@"; do + process_args $arg +done + +NOSETESTS="nosetests ${noseargs}" + +if [ $just_pep8 -ne 0 ]; then + wrapper "pep8 -r --show-pep8 novaclient tests" +else + wrapper $NOSETESTS +fi diff --git a/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py index f53a029f9..c6d47cf88 100644 --- a/tests/v1_1/test_shell.py +++ b/tests/v1_1/test_shell.py @@ -67,7 +67,8 @@ class ShellTest(utils.TestCase): testfile = os.path.join(os.path.dirname(__file__), 'testfile.txt') expected_file_data = open(testfile).read().encode('base64') - cmd = 'boot some-server --image 1 --file /tmp/foo=%s --file /tmp/bar=%s' + cmd = 'boot some-server --image 1 ' \ + '--file /tmp/foo=%s --file /tmp/bar=%s' self.run_command(cmd % (testfile, testfile)) self.assert_called_anytime(