From 25a29bc237c0a4072470bd8f59de0af4c0ef351d Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Tue, 7 May 2013 18:59:46 +0200 Subject: [PATCH] Fix skips done in the test suite by using testtools skipIf The shipped skip_if function was broken as skipIf is already a decorator. Change-Id: Ifc5c3a7878fa047fe1a807c43d91fe34bc7b4081 --- heat/tests/test_s3.py | 21 +++++++++++---------- heat/tests/test_swift.py | 21 +++++++++++---------- heat/tests/test_volume.py | 9 ++++++--- heat/tests/utils.py | 18 ------------------ 4 files changed, 28 insertions(+), 41 deletions(-) diff --git a/heat/tests/test_s3.py b/heat/tests/test_s3.py index 7bc6906a..e60874ca 100644 --- a/heat/tests/test_s3.py +++ b/heat/tests/test_s3.py @@ -18,6 +18,8 @@ import re import mox +from testtools import skipIf + from heat.common import context from heat.common import template_format from heat.openstack.common.importutils import try_import @@ -26,13 +28,12 @@ from heat.engine import parser from heat.engine import scheduler from heat.tests.common import HeatTestCase from heat.tests.utils import setup_dummy_db -from heat.tests.utils import skip_if swiftclient = try_import('swiftclient.client') class s3Test(HeatTestCase): - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def setUp(self): super(s3Test, self).setUp() self.m.CreateMock(swiftclient.Connection) @@ -69,7 +70,7 @@ class s3Test(HeatTestCase): self.assertEqual(s3.S3Bucket.CREATE_COMPLETE, resource.state) return resource - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_create_container_name(self): self.m.ReplayAll() t = self.load_template() @@ -80,7 +81,7 @@ class s3Test(HeatTestCase): self.assertTrue(re.match(self.container_pattern, resource._create_container_name())) - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_attributes(self): swiftclient.Connection.put_container( mox.Regex(self.container_pattern), @@ -118,7 +119,7 @@ class s3Test(HeatTestCase): resource.delete() self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_public_read(self): swiftclient.Connection.put_container( mox.Regex(self.container_pattern), @@ -136,7 +137,7 @@ class s3Test(HeatTestCase): resource.delete() self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_public_read_write(self): swiftclient.Connection.put_container( mox.Regex(self.container_pattern), @@ -154,7 +155,7 @@ class s3Test(HeatTestCase): resource.delete() self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_authenticated_read(self): swiftclient.Connection.put_container( mox.Regex(self.container_pattern), @@ -172,7 +173,7 @@ class s3Test(HeatTestCase): resource.delete() self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_website(self): swiftclient.Connection.put_container( @@ -191,7 +192,7 @@ class s3Test(HeatTestCase): resource.delete() self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_delete_exception(self): swiftclient.Connection.put_container( @@ -210,7 +211,7 @@ class s3Test(HeatTestCase): self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_delete_retain(self): # first run, with retain policy diff --git a/heat/tests/test_swift.py b/heat/tests/test_swift.py index da9a2d16..aa34bcc6 100644 --- a/heat/tests/test_swift.py +++ b/heat/tests/test_swift.py @@ -18,6 +18,8 @@ import re import mox +from testtools import skipIf + from heat.common import context from heat.common import template_format from heat.openstack.common.importutils import try_import @@ -26,13 +28,12 @@ from heat.engine import parser from heat.engine import scheduler from heat.tests.common import HeatTestCase from heat.tests.utils import setup_dummy_db -from heat.tests.utils import skip_if swiftclient = try_import('swiftclient.client') class swiftTest(HeatTestCase): - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def setUp(self): super(swiftTest, self).setUp() self.m.CreateMock(swiftclient.Connection) @@ -71,7 +72,7 @@ class swiftTest(HeatTestCase): self.assertEqual(swift.SwiftContainer.CREATE_COMPLETE, resource.state) return resource - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_create_container_name(self): self.m.ReplayAll() t = self.load_template() @@ -87,7 +88,7 @@ class swiftTest(HeatTestCase): 'the_name', resource._create_container_name('the_name')) - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_build_meta_headers(self): self.m.UnsetStubs() self.assertEqual({}, swift.SwiftContainer._build_meta_headers({})) @@ -101,7 +102,7 @@ class swiftTest(HeatTestCase): "Web-Error": "error.html" })) - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_attributes(self): headers = { "content-length": "0", @@ -156,7 +157,7 @@ class swiftTest(HeatTestCase): resource.delete() self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_public_read(self): swiftclient.Connection.put_container( mox.Regex(self.container_pattern), @@ -174,7 +175,7 @@ class swiftTest(HeatTestCase): resource.delete() self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_public_read_write(self): swiftclient.Connection.put_container( mox.Regex(self.container_pattern), @@ -193,7 +194,7 @@ class swiftTest(HeatTestCase): resource.delete() self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_website(self): swiftclient.Connection.put_container( @@ -212,7 +213,7 @@ class swiftTest(HeatTestCase): resource.delete() self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_delete_exception(self): swiftclient.Connection.put_container( @@ -231,7 +232,7 @@ class swiftTest(HeatTestCase): self.m.VerifyAll() - @skip_if(swiftclient is None, 'unable to import swiftclient') + @skipIf(swiftclient is None, 'unable to import swiftclient') def test_delete_retain(self): # first run, with retain policy diff --git a/heat/tests/test_volume.py b/heat/tests/test_volume.py index 4041f1aa..624cb20c 100644 --- a/heat/tests/test_volume.py +++ b/heat/tests/test_volume.py @@ -17,6 +17,8 @@ import os import eventlet +from testtools import skipIf + from heat.common import context from heat.common import exception from heat.common import template_format @@ -27,7 +29,7 @@ from heat.engine import clients from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests.v1_1 import fakes -from heat.tests.utils import setup_dummy_db, skip_if +from heat.tests.utils import setup_dummy_db from cinderclient.v1 import client as cinderclient @@ -236,7 +238,7 @@ class VolumeTest(HeatTestCase): self.m.VerifyAll() - @skip_if(volume_backups is None, 'unable to import volume_backups') + @skipIf(volume_backups is None, 'unable to import volume_backups') def test_snapshot(self): stack_name = 'test_volume_stack' fv = FakeVolume('creating', 'available') @@ -268,7 +270,7 @@ class VolumeTest(HeatTestCase): self.m.VerifyAll() - @skip_if(volume_backups is None, 'unable to import volume_backups') + @skipIf(volume_backups is None, 'unable to import volume_backups') def test_snapshot_error(self): stack_name = 'test_volume_stack' fv = FakeVolume('creating', 'available') @@ -298,6 +300,7 @@ class VolumeTest(HeatTestCase): self.m.VerifyAll() + @skipIf(volume_backups is None, 'unable to import volume_backups') def test_snapshot_no_volume(self): stack_name = 'test_volume_stack' fv = FakeVolume('creating', 'error') diff --git a/heat/tests/utils.py b/heat/tests/utils.py index 4f2900ed..0e46ce0b 100644 --- a/heat/tests/utils.py +++ b/heat/tests/utils.py @@ -15,8 +15,6 @@ import sys import functools -from testtools import skipIf - from heat.common import context from heat.engine import parser @@ -24,22 +22,6 @@ from heat.db.sqlalchemy.session import get_engine from heat.db import migration -class skip_if(object): - """Decorator that skips a test if condition is true.""" - def __init__(self, condition, msg): - self.condition = condition - self.message = msg - - def __call__(self, func): - def _skipper(*args, **kw): - """Wrapped skipper function.""" - skipIf(self.condition, self.message) - func(*args, **kw) - _skipper.__name__ = func.__name__ - _skipper.__doc__ = func.__doc__ - return _skipper - - def stack_delete_after(test_fn): """ Decorator which calls test class self.stack.delete() -- 2.45.2