summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-09-20 17:19:05 +0000
committerJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-09-20 19:37:34 +0000
commitc82dba22c24cd7cd4d7ce3629da24644414cb374 (patch)
tree2e4665ad1fb30baa6b4c935e0674c75844308c7e /nova/tests
parent7cdd6c3fb4aeecb4a0441385576206bb17cdecfe (diff)
Clarify dangerous use of exceptions in unit tests
Also, update unit tests to use more specific exception where possible to make auditing easier in the future. Change-Id: I4906e2f8e3ebacf0587f1471ca8dd46c73edc17a
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/test_common.py12
-rw-r--r--nova/tests/compute/test_compute.py4
-rw-r--r--nova/tests/test_db_api.py3
3 files changed, 7 insertions, 12 deletions
diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py
index 250a199e8..4ebd49ca2 100644
--- a/nova/tests/api/openstack/test_common.py
+++ b/nova/tests/api/openstack/test_common.py
@@ -290,10 +290,8 @@ class MiscFunctionsTest(test.TestCase):
try:
common.raise_http_conflict_for_instance_invalid_state(exc,
'meow')
- except Exception, e:
- self.assertTrue(isinstance(e, webob.exc.HTTPConflict))
- msg = str(e)
- self.assertEqual(msg,
+ except webob.exc.HTTPConflict as e:
+ self.assertEqual(unicode(e),
"Cannot 'meow' while instance is in fake_attr fake_state")
else:
self.fail("webob.exc.HTTPConflict was not raised")
@@ -303,10 +301,8 @@ class MiscFunctionsTest(test.TestCase):
try:
common.raise_http_conflict_for_instance_invalid_state(exc,
'meow')
- except Exception, e:
- self.assertTrue(isinstance(e, webob.exc.HTTPConflict))
- msg = str(e)
- self.assertEqual(msg,
+ except webob.exc.HTTPConflict as e:
+ self.assertEqual(unicode(e),
"Instance is in an invalid state for 'meow'")
else:
self.fail("webob.exc.HTTPConflict was not raised")
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 63af33153..747774fa4 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -2264,7 +2264,7 @@ class ComputeTestCase(BaseTestCase):
try:
raise NotImplementedError('test')
- except Exception:
+ except NotImplementedError:
exc_info = sys.exc_info()
self.stubs.Set(nova.db, 'instance_fault_create', fake_db_fault_create)
@@ -2292,7 +2292,7 @@ class ComputeTestCase(BaseTestCase):
try:
raise user_exc
- except Exception:
+ except exception.Invalid:
exc_info = sys.exc_info()
self.stubs.Set(nova.db, 'instance_fault_create', fake_db_fault_create)
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 641c7c8cd..e434faaad 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -46,11 +46,10 @@ class DbApiTestCase(test.TestCase):
return db.instance_create(self.context, args)
def test_ec2_ids_not_found_are_printable(self):
-
def check_exc_format(method):
try:
method(self.context, 'fake')
- except Exception as exc:
+ except exception.NotFound as exc:
self.assertTrue('fake' in unicode(exc))
check_exc_format(db.get_ec2_volume_id_by_uuid)