Raise exception instances, not exception classes.

Raising raw exception classes works, but is old deprecated syntax, and
may bite us later.

Change-Id: I03f41da267ce5cbfc5ea98c531acc9a9b13e082a
This commit is contained in:
David Ripton 2013-05-28 16:21:25 -04:00
parent a081faa418
commit d0e50669d1
7 changed files with 21 additions and 21 deletions

View File

@ -66,19 +66,19 @@ class ReadOnlyDict(UserDict.IterableUserDict):
self.update(source)
def __setitem__(self, key, item):
raise TypeError
raise TypeError()
def __delitem__(self, key):
raise TypeError
raise TypeError()
def clear(self):
raise TypeError
raise TypeError()
def pop(self, key, *args):
raise TypeError
raise TypeError()
def popitem(self):
raise TypeError
raise TypeError()
def update(self, source=None):
if source is None:
@ -88,7 +88,7 @@ class ReadOnlyDict(UserDict.IterableUserDict):
elif isinstance(source, type({})):
self.data = source
else:
raise TypeError
raise TypeError()
class HostState(object):

View File

@ -47,7 +47,7 @@ class FakeCoverage(object):
def stop(self):
if not self.started:
raise AssertionError
raise AssertionError()
self.started = False
def report(self, file):

View File

@ -7462,7 +7462,7 @@ class ComputeAPITestCase(BaseTestCase):
def fake_libvirt_driver_detach_volume_fails(*args, **kwargs):
called['fake_libvirt_driver_detach_volume_fails'] = True
raise AttributeError
raise AttributeError()
def fake_roll_detaching(*args, **kwargs):
called['fake_roll_detaching'] = True

View File

@ -217,19 +217,19 @@ class FakeLDAP(object):
def simple_bind_s(self, dn, password):
"""This method is ignored, but provided for compatibility."""
if server_fail:
raise SERVER_DOWN
raise SERVER_DOWN()
pass
def unbind_s(self):
"""This method is ignored, but provided for compatibility."""
if server_fail:
raise SERVER_DOWN
raise SERVER_DOWN()
pass
def add_s(self, dn, attr):
"""Add an object with the specified attributes at dn."""
if server_fail:
raise SERVER_DOWN
raise SERVER_DOWN()
key = "%s%s" % (self.__prefix, dn)
value_dict = dict([(k, _to_json(v)) for k, v in attr])
@ -238,7 +238,7 @@ class FakeLDAP(object):
def delete_s(self, dn):
"""Remove the ldap object at specified dn."""
if server_fail:
raise SERVER_DOWN
raise SERVER_DOWN()
Store.instance().delete("%s%s" % (self.__prefix, dn))
@ -252,7 +252,7 @@ class FakeLDAP(object):
"""
if server_fail:
raise SERVER_DOWN
raise SERVER_DOWN()
store = Store.instance()
key = "%s%s" % (self.__prefix, dn)
@ -292,7 +292,7 @@ class FakeLDAP(object):
"""
if server_fail:
raise SERVER_DOWN
raise SERVER_DOWN()
if scope != SCOPE_BASE and scope != SCOPE_SUBTREE:
raise NotImplementedError(str(scope))

View File

@ -325,7 +325,7 @@ class GenericUtilsTestCase(test.TestCase):
def test_read_file_as_root(self):
def fake_execute(*args, **kwargs):
if args[1] == 'bad':
raise processutils.ProcessExecutionError
raise processutils.ProcessExecutionError()
return 'fakecontents', None
self.stubs.Set(utils, 'execute', fake_execute)

View File

@ -175,13 +175,13 @@ class Image(object):
return can_fallocate
def snapshot_create(self):
raise NotImplementedError
raise NotImplementedError()
def snapshot_extract(self, target, out_format):
raise NotImplementedError
raise NotImplementedError()
def snapshot_delete(self):
raise NotImplementedError
raise NotImplementedError()
class Raw(Image):

View File

@ -97,15 +97,15 @@ class VMwareHTTPFile(object):
def write(self, data):
"""Write data to the file."""
raise NotImplementedError
raise NotImplementedError()
def read(self, chunk_size):
"""Read a chunk of data."""
raise NotImplementedError
raise NotImplementedError()
def get_size(self):
"""Get size of the file to be read."""
raise NotImplementedError
raise NotImplementedError()
class VMwareHTTPWriteFile(VMwareHTTPFile):