Implemented @utils.skip_test, @utils.skip_unless and @utils.skip_if functionality in glance/test/utils.py. Added glance/tests/unit/test_skip_examples.py which contains example skip case usages.

Fixed issue where ./run_tests.sh would not execute pep8. Fixed couple of pep8 violations in test_skip_examples.py

Change-Id: Id6eaa8768b663b4638fbca0e3bdf72b74969150a
This commit is contained in:
Justin Shepherd 2011-08-04 11:00:00 -05:00
parent 3aa1701e07
commit 486deeabd6
6 changed files with 105 additions and 3 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.pyc
*.log
.glance-venv
tests.sqlite

View File

@ -79,5 +79,5 @@ def lookup_by_registry(registry, image_id):
adapter = REGISTRY_ADAPTERS[registry]
except KeyError:
raise UnknownImageRegistry("'%s' not found" % registry)
return adapter.lookup(image_id)

View File

@ -0,0 +1,48 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010-2011 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 unittest
from glance.tests import utils
class TestSkipExamples(unittest.TestCase):
test_counter = 0
@utils.skip_test("Example usage of @utils.skip_test()")
def test_skip_test_example(self):
self.fail("skip_test failed to work properly.")
@utils.skip_if(True, "Example usage of @utils.skip_if()")
def test_skip_if_example(self):
self.fail("skip_if failed to work properly.")
@utils.skip_unless(False, "Example usage of @utils.skip_unless()")
def test_skip_unless_example(self):
self.fail("skip_unless failed to work properly.")
@utils.skip_if(False, "This test case should never be skipped.")
def test_001_increase_test_counter(self):
TestSkipExamples.test_counter += 1
@utils.skip_unless(True, "This test case should never be skipped.")
def test_002_increase_test_counter(self):
TestSkipExamples.test_counter += 1
def test_003_verify_test_counter(self):
self.assertEquals(TestSkipExamples.test_counter, 2,
"Tests were not skipped appropriately")

View File

@ -21,6 +21,56 @@ import os
import socket
import subprocess
import nose.plugins.skip
class skip_test(object):
"""Decorator that skips a test."""
def __init__(self, msg):
self.message = msg
def __call__(self, func):
def _skipper(*args, **kw):
"""Wrapped skipper function."""
raise nose.SkipTest(self.message)
_skipper.__name__ = func.__name__
_skipper.__doc__ = func.__doc__
return _skipper
class skip_if(object):
"""Decorator that skips a test if contition is true."""
def __init__(self, condition, msg):
self.condition = condition
self.message = msg
def __call__(self, func):
def _skipper(*args, **kw):
"""Wrapped skipper function."""
if self.condition:
raise nose.SkipTest(self.message)
func(*args, **kw)
_skipper.__name__ = func.__name__
_skipper.__doc__ = func.__doc__
return _skipper
class skip_unless(object):
"""Decorator that skips a test if condition is not true."""
def __init__(self, condition, msg):
self.condition = condition
self.message = msg
def __call__(self, func):
def _skipper(*args, **kw):
"""Wrapped skipper function."""
if not self.condition:
raise nose.SkipTest(self.message)
func(*args, **kw)
_skipper.__name__ = func.__name__
_skipper.__doc__ = func.__doc__
return _skipper
def execute(cmd, raise_error=True):
"""

View File

@ -234,7 +234,7 @@ class GlanceTestResult(result.TextTestResult):
if stream is not None:
if self.showAll:
message = [label]
detail = result._exception_details(err[1])
detail = result._exception_detail(err[1])
if detail:
message.append(detail)
stream.writeln(": ".join(message))

View File

@ -59,7 +59,7 @@ function run_pep8 {
PEP8_EXCLUDE=vcsversion.py
PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-pep8 --show-source"
PEP8_INCLUDE="bin/* glance tools setup.py run_tests.py"
pep8 $PEP8_OPTIONS $PEP8_INCLUDE
${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE
}