Replace StandardError with Exception

StandardError was removed in Python3 and instead
Exception should be used.

Signed-off-by: Robert Kuska <rkuska@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
Robert Kuska
2015-08-24 12:40:33 +02:00
committed by Jan Cholasta
parent 34e6c3ea05
commit 01da4a8de3
21 changed files with 49 additions and 49 deletions

View File

@@ -46,7 +46,7 @@ def use_keytab(principal, keytab):
conn.connect(autobind=ipaldap.AUTOBIND_DISABLED)
conn.disconnect()
except gssapi.exceptions.GSSError as e:
raise StandardError('Unable to bind to LDAP. Error initializing principal %s in %s: %s' % (principal, keytab, str(e)))
raise Exception('Unable to bind to LDAP. Error initializing principal %s in %s: %s' % (principal, keytab, str(e)))
finally:
os.environ.pop('KRB5CCNAME', None)
if tmpdir:
@@ -138,7 +138,7 @@ class test_ipagetkeytab(cmdline_test):
"""
try:
use_keytab(self.service_princ, self.keytabname)
except StandardError as errmsg:
except Exception as errmsg:
assert('Unable to bind to LDAP. Error initializing principal' in str(errmsg))
def test_9_cleanup(self):

View File

@@ -90,9 +90,9 @@ class test_Connectible(ClassChecker):
assert conn.conn == 'The connection.'
assert conn.disconnect == o.disconnect
# Test that StandardError is raised if already connected:
# Test that Exception is raised if already connected:
m = "connect: 'context.%s' already exists in thread %r"
e = raises(StandardError, o.connect, *args, **kw)
e = raises(Exception, o.connect, *args, **kw)
assert str(e) == m % ('example', threading.currentThread().getName())
# Double check that it works after deleting context.example:
@@ -121,7 +121,7 @@ class test_Connectible(ClassChecker):
o = example(api, shared_instance=True)
m = "disconnect: 'context.%s' does not exist in thread %r"
e = raises(StandardError, o.disconnect)
e = raises(Exception, o.disconnect)
assert str(e) == m % ('example', threading.currentThread().getName())
context.example = 'The connection.'

View File

@@ -166,7 +166,7 @@ class test_Env(ClassChecker):
assert o.__islocked__() is False
o.__lock__()
assert o.__islocked__() is True
e = raises(StandardError, o.__lock__)
e = raises(Exception, o.__lock__)
assert str(e) == 'Env.__lock__() already called'
# Also test with base.lock() function:
@@ -429,7 +429,7 @@ class test_Env(ClassChecker):
assert o._isdone('_bootstrap') is False
o._bootstrap(**overrides)
assert o._isdone('_bootstrap') is True
e = raises(StandardError, o._bootstrap)
e = raises(Exception, o._bootstrap)
assert str(e) == 'Env._bootstrap() already called'
return (o, home)
@@ -512,7 +512,7 @@ class test_Env(ClassChecker):
assert key in o
# Check that it can't be called twice:
e = raises(StandardError, o._finalize_core)
e = raises(Exception, o._finalize_core)
assert str(e) == 'Env._finalize_core() already called'
return (o, home)
@@ -586,7 +586,7 @@ class test_Env(ClassChecker):
assert o._isdone('_finalize') is True
# Check that it can't be called twice:
e = raises(StandardError, o._finalize)
e = raises(Exception, o._finalize)
assert str(e) == 'Env._finalize() already called'
# Check that _finalize() calls __lock__()
@@ -594,7 +594,7 @@ class test_Env(ClassChecker):
assert o.__islocked__() is False
o._finalize()
assert o.__islocked__() is True
e = raises(StandardError, o.__lock__)
e = raises(Exception, o.__lock__)
assert str(e) == 'Env.__lock__() already called'
# Check that **lastchance works

View File

@@ -45,7 +45,7 @@ class PrivateExceptionTester(object):
def __get_klass(self):
if self.__klass is None:
self.__klass = self._klass
assert issubclass(self.__klass, StandardError)
assert issubclass(self.__klass, Exception)
assert issubclass(self.__klass, errors.PrivateError)
assert not issubclass(self.__klass, errors.PublicError)
return self.__klass
@@ -55,7 +55,7 @@ class PrivateExceptionTester(object):
for (key, value) in kw.items():
assert not hasattr(self.klass, key), key
inst = self.klass(**kw)
assert isinstance(inst, StandardError)
assert isinstance(inst, Exception)
assert isinstance(inst, errors.PrivateError)
assert isinstance(inst, self.klass)
assert not isinstance(inst, errors.PublicError)
@@ -203,7 +203,7 @@ class PublicExceptionTester(object):
def __get_klass(self):
if self.__klass is None:
self.__klass = self._klass
assert issubclass(self.__klass, StandardError)
assert issubclass(self.__klass, Exception)
assert issubclass(self.__klass, errors.PublicError)
assert not issubclass(self.__klass, errors.PrivateError)
assert type(self.__klass.errno) is int
@@ -234,7 +234,7 @@ class test_PublicError(PublicExceptionTester):
Test the `ipalib.errors.PublicError` exception.
"""
_klass = errors.PublicError
required_classes = StandardError, errors.PublicError
required_classes = Exception, errors.PublicError
def test_init(self):
message = u'The translated, interpolated message'
@@ -375,7 +375,7 @@ class BaseMessagesTest(object):
class test_PublicErrors(object):
message_list = errors.public_errors
errno_range = list(range(900, 5999))
required_classes = (StandardError, errors.PublicError)
required_classes = (Exception, errors.PublicError)
texts = errors._texts
def extratest(self, cls):

View File

@@ -80,7 +80,7 @@ class test_Plugin(ClassChecker):
# whose names conflict with the logger methods set in Plugin.__init__():
class check(self.cls):
info = 'whatever'
e = raises(StandardError, check, api)
e = raises(Exception, check, api)
assert str(e) == \
"info is already bound to ipatests.test_ipalib.test_plugable.check()"
@@ -257,7 +257,7 @@ class test_API(ClassChecker):
assert inst.method(7) == 7 + b
# Test that calling finilize again raises AssertionError:
e = raises(StandardError, api.finalize)
e = raises(Exception, api.finalize)
assert str(e) == 'API.finalize() already called', str(e)
def test_bootstrap(self):
@@ -273,7 +273,7 @@ class test_API(ClassChecker):
assert o.env._isdone('_bootstrap') is True
assert o.env._isdone('_finalize_core') is True
assert o.env.my_test_override == 'Hello, world!'
e = raises(StandardError, o.bootstrap)
e = raises(Exception, o.bootstrap)
assert str(e) == 'API.bootstrap() already called'
def test_load_plugins(self):
@@ -286,5 +286,5 @@ class test_API(ClassChecker):
o.load_plugins()
assert o.isdone('bootstrap') is True
assert o.isdone('load_plugins') is True
e = raises(StandardError, o.load_plugins)
e = raises(Exception, o.load_plugins)
assert str(e) == 'API.load_plugins() already called'

View File

@@ -173,8 +173,8 @@ class test_session(object):
assert inst['foo'] is app1
assert list(inst) == ['foo']
# Test that StandardError is raise if trying override a mount:
e = raises(StandardError, inst.mount, app2, 'foo')
# Test that Exception is raise if trying override a mount:
e = raises(Exception, inst.mount, app2, 'foo')
assert str(e) == '%s.mount(): cannot replace %r with %r at %r' % (
'wsgi_dispatch', app1, app2, 'foo'
)

View File

@@ -313,7 +313,7 @@ class Declarative(XMLRPC_test):
name = klass.__name__
try:
output = api.Command[cmd](*args, **options)
except StandardError as e:
except Exception as e:
pass
else:
raise AssertionError(
@@ -336,7 +336,7 @@ class Declarative(XMLRPC_test):
e = None
try:
output = api.Command[cmd](*args, **options)
except StandardError as e:
except Exception as e:
pass
if not expected(e, output):
raise AssertionError(