]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Migrate test base class to testtools.
authorMonty Taylor <mordred@inaugust.com>
Sat, 25 May 2013 07:43:40 +0000 (09:43 +0200)
committerMonty Taylor <mordred@inaugust.com>
Sat, 25 May 2013 07:43:40 +0000 (09:43 +0200)
This is stricter, but also provides plumbing for more advanced things
like fixtures and testscenarios.

Change-Id: I607b50390708ca3caa9799ef0b27007df5045a6c

14 files changed:
HACKING.rst
heat/tests/test_api_cloudwatch.py
heat/tests/test_cli.py
heat/tests/test_dependencies.py
heat/tests/test_event.py
heat/tests/test_identifier.py
heat/tests/test_parameters.py
heat/tests/test_plugin_loader.py
heat/tests/test_properties.py
heat/tests/test_resource.py
heat/tests/test_rpc_client.py
heat/tests/test_security_group.py
heat/tests/test_short_id.py
test-requirements.txt

index 1ecaae91c288c86c262b86e69fcfec88e2e023d0..e20cf54a3808c165bef9fe50c98d6b84b02a79a7 100644 (file)
@@ -86,9 +86,9 @@ Example::
   import random
   import StringIO
   import time
-  import unittest
 
   import eventlet
+  import testtools
   import webob.exc
 
   import heat.api.ec2
index 82c46e90e9bc72daa32259565a9dac94d7278942..98cf2f7dff9604201174ff0948c8ad705a76ef47 100644 (file)
@@ -524,7 +524,4 @@ class WatchControllerTest(HeatTestCase):
         cfgopts = DummyConfig()
         self.controller = watches.WatchController(options=cfgopts)
         self.controller.policy.policy_path = None
-
-    def tearDown(self):
-        self.m.VerifyAll()
-        super(WatchControllerTest, self).tearDown()
+        self.addCleanup(self.m.VerifyAll)
index adb37d62bb65bf117b2cbc372914ce7ab3c028ce..4848e88fa1242630b6f376a325df0f8ff42e92ff 100644 (file)
@@ -13,7 +13,7 @@
 #    under the License.
 
 
-import unittest
+import testtools
 import heat
 import os
 import subprocess
@@ -21,7 +21,7 @@ import subprocess
 basepath = os.path.join(heat.__path__[0], os.path.pardir)
 
 
-class CliTest(unittest.TestCase):
+class CliTest(testtools.TestCase):
 
     def test_heat_cfn(self):
             self.bin_test_run('heat-cfn')
index d04d44f11341e8c22439ddedc15ded0e81c4e417..eba83d093be72d73911c2cae84216a9df94f21e0 100644 (file)
 #    under the License.
 
 
-import unittest
+import testtools
 
 from heat.engine.dependencies import Dependencies
 from heat.engine.dependencies import CircularDependencyException
 
 
-class dependenciesTest(unittest.TestCase):
+class dependenciesTest(testtools.TestCase):
 
     def _dep_test(self, func, checkorder, deps):
         nodes = set.union(*[set(e) for e in deps])
index 3d07b6f6a39526ffe4b118ad29a28f849f5fa034..812fc42dd7993b0271a9074b74e97b16dfc3ac58 100644 (file)
@@ -61,10 +61,7 @@ class EventTest(HeatTestCase):
 
         self.resource = self.stack['EventTestResource']
         self.resource._store()
-
-    def tearDown(self):
-        db_api.stack_delete(self.ctx, self.stack.id)
-        super(EventTest, self).tearDown()
+        self.addCleanup(db_api.stack_delete, self.ctx, self.stack.id)
 
     def test_load(self):
         self.resource.resource_id_set('resource_physical_id')
index f44749e2ee770447db89299eed34bee7993e7b2f..0205eff74b1bb831bbe5ee52f46d5bad1db46f9a 100644 (file)
 #    under the License.
 
 
-import unittest
+import testtools
 
 from heat.common import identifier
 
 
-class IdentifierTest(unittest.TestCase):
+class IdentifierTest(testtools.TestCase):
     url_prefix = 'http://1.2.3.4/foo/'
 
     def test_attrs(self):
@@ -354,7 +354,7 @@ class IdentifierTest(unittest.TestCase):
         self.assertEqual(hi._path_components(), ['p1', 'p2', 'p3'])
 
 
-class ResourceIdentifierTest(unittest.TestCase):
+class ResourceIdentifierTest(testtools.TestCase):
     def test_resource_init_no_path(self):
         si = identifier.HeatIdentifier('t', 's', 'i')
         ri = identifier.ResourceIdentifier(resource_name='r', **si)
@@ -385,7 +385,7 @@ class ResourceIdentifierTest(unittest.TestCase):
                           't', 's', 'i', 'p', 'r/r')
 
 
-class EventIdentifierTest(unittest.TestCase):
+class EventIdentifierTest(testtools.TestCase):
     def test_event_init(self):
         si = identifier.HeatIdentifier('t', 's', 'i')
         pi = identifier.ResourceIdentifier(resource_name='p', **si)
index b9f61e213774e5d5b8837b82220ae58515cf88c6..bfa3672ba9761856c4c8c1e9cf32e47287b0d7b6 100644 (file)
 #    under the License.
 
 
-import unittest
+import testtools
 import json
 
 from heat.engine import parameters
 
 
-class ParameterTest(unittest.TestCase):
+class ParameterTest(testtools.TestCase):
     def test_new_string(self):
         p = parameters.Parameter('p', {'Type': 'String'})
         self.assertTrue(isinstance(p, parameters.StringParam))
@@ -268,7 +268,7 @@ params_schema = json.loads('''{
 }''')
 
 
-class ParametersTest(unittest.TestCase):
+class ParametersTest(testtools.TestCase):
     def test_pseudo_params(self):
         params = parameters.Parameters('test_stack', {"Parameters": {}})
 
index c72ddd8872a473c5893dfdb88b1c93a1527856dd..9059ae4dc5e0f622ba459c528102f77e672b0131 100644 (file)
 
 import pkgutil
 import sys
-import unittest
+import testtools
 
 import heat.engine
 from heat.common import plugin_loader
 
 
-class PluginLoaderTest(unittest.TestCase):
+class PluginLoaderTest(testtools.TestCase):
     def test_module_name(self):
         self.assertEqual(plugin_loader._module_name('foo.bar', 'blarg.wibble'),
                          'foo.bar.blarg.wibble')
index 28dc4d1d9f9433ed4670da527cc612232a72fbe4..f3acff60e03598154db78eafd42f653da9fd2048 100644 (file)
 #    under the License.
 
 
-import unittest
+import testtools
 
 from heat.engine import properties
 from heat.common import exception
 
 
-class PropertyTest(unittest.TestCase):
+class PropertyTest(testtools.TestCase):
     def test_required_default(self):
         p = properties.Property({'Type': 'String'})
         self.assertFalse(p.required())
@@ -256,8 +256,9 @@ class PropertyTest(unittest.TestCase):
         self.assertRaises(TypeError, p.validate_data, [42, 'fish'])
 
 
-class PropertiesTest(unittest.TestCase):
+class PropertiesTest(testtools.TestCase):
     def setUp(self):
+        super(PropertiesTest, self).setUp()
         schema = {
             'int': {'Type': 'Integer'},
             'string': {'Type': 'String'},
@@ -301,7 +302,7 @@ class PropertiesTest(unittest.TestCase):
         self.assertEqual(self.props.get('foo', 'wibble'), 'wibble')
 
 
-class PropertiesValidationTest(unittest.TestCase):
+class PropertiesValidationTest(testtools.TestCase):
     def test_required(self):
         schema = {'foo': {'Type': 'String', 'Required': True}}
         props = properties.Properties(schema, {'foo': 'bar'})
index 431a0f886c2a549d8c5fe566c1556118c4c6bc6b..edc7efd37051e322b7720ed6358843fbcf683bab 100644 (file)
@@ -376,10 +376,7 @@ class MetadataTest(HeatTestCase):
         self.res = generic_rsrc.GenericResource('metadata_resource',
                                                 tmpl, self.stack)
         scheduler.TaskRunner(self.res.create)()
-
-    def tearDown(self):
-        self.stack.delete()
-        super(HeatTestCase, self).tearDown()
+        self.addCleanup(self.stack.delete)
 
     def test_read_initial(self):
         self.assertEqual(self.res.metadata, {'Test': 'Initial metadata'})
index 7e69489019f7a267f04f4351d8e3e7fd43bd49cf..c397d9ca585fbbdc7df6597697c46fb3976671cd 100644 (file)
@@ -21,7 +21,7 @@ Unit Tests for heat.rpc.client
 
 from oslo.config import cfg
 import stubout
-import unittest
+import testtools
 
 from heat.common import config
 from heat.common import context
@@ -31,7 +31,7 @@ from heat.rpc import client as rpc_client
 from heat.openstack.common import rpc
 
 
-class EngineRpcAPITestCase(unittest.TestCase):
+class EngineRpcAPITestCase(testtools.TestCase):
 
     def setUp(self):
         config.register_engine_opts()
index 205820232c0922a32808e87f148a57e7c066ee02..e25ea1705387ae697fbeec0fe0dc59452b27451a 100644 (file)
@@ -101,9 +101,6 @@ Resources:
             quantumclient.Client, 'delete_security_group_rule')
         self.m.StubOutWithMock(quantumclient.Client, 'delete_security_group')
 
-    def tearDown(self):
-        super(SecurityGroupTest, self).tearDown()
-
     def create_stack(self, template):
         t = template_format.parse(template)
         self.stack = self.parse_stack(t)
index fe48309e3262fb422b40c35d601d1c3fb67ef00b..b9b0f7414c25ae048839fad4b9884020febcef8a 100644 (file)
 #    under the License.
 
 
-import unittest
+import testtools
 
 from heat.common import short_id
 import uuid
 
 
-class ShortIdTest(unittest.TestCase):
+class ShortIdTest(testtools.TestCase):
 
     def test_byte_string_8(self):
         self.assertEqual(short_id._to_byte_string(0xab, 8), '\xab')
index 4723abe8c006eca4de16139cb739223870ec13b4..45b5c8e1decc3e49536c84f112b60a84d847729d 100644 (file)
@@ -10,6 +10,7 @@ hacking>=0.5.3,<0.6
 coverage
 discover
 mox==0.5.3
+testtools>=0.9.29
 testrepository>=0.0.13
 paramiko
 python-glanceclient