mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
37: Renamed tstutil.yes_raises() to raises(); changed test_plugable.py to use raises() throughout
This commit is contained in:
@@ -115,35 +115,14 @@ def test_Proxy():
|
|||||||
i = do_something()
|
i = do_something()
|
||||||
p = CommandProxy(i)
|
p = CommandProxy(i)
|
||||||
assert getattr(i, name)(1) == 4
|
assert getattr(i, name)(1) == 4
|
||||||
raised = False
|
tstutil.raises(AttributeError, getattr, p, name)
|
||||||
try:
|
|
||||||
getattr(p, name)
|
|
||||||
except AttributeError:
|
|
||||||
raised = True
|
|
||||||
assert raised
|
|
||||||
|
|
||||||
# Test that attributes are read-only:
|
# Test that attributes are read-only:
|
||||||
name = 'validate'
|
name = 'validate'
|
||||||
i = do_something()
|
i = do_something()
|
||||||
p = CommandProxy(i)
|
p = CommandProxy(i)
|
||||||
assert getattr(p, name)(1) == 3
|
assert getattr(p, name)(1) == 3
|
||||||
raised = False
|
assert tstutil.read_only(p, name)(1) == 3
|
||||||
try:
|
|
||||||
# Test __setattr__()
|
|
||||||
setattr(p, name, 'new_object')
|
|
||||||
except AttributeError:
|
|
||||||
raised = True
|
|
||||||
assert raised
|
|
||||||
raised = False
|
|
||||||
try:
|
|
||||||
# Test __delattr__()
|
|
||||||
delattr(p, name)
|
|
||||||
except AttributeError:
|
|
||||||
raised = True
|
|
||||||
assert raised
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_Registrar():
|
def test_Registrar():
|
||||||
@@ -166,21 +145,11 @@ def test_Registrar():
|
|||||||
|
|
||||||
# Check that TypeError is raised trying to register something that isn't
|
# Check that TypeError is raised trying to register something that isn't
|
||||||
# a class:
|
# a class:
|
||||||
raised = False
|
tstutil.raises(TypeError, r, plugin1())
|
||||||
try:
|
|
||||||
r(plugin1())
|
|
||||||
except TypeError:
|
|
||||||
raised = True
|
|
||||||
assert raised
|
|
||||||
|
|
||||||
# Check that SubclassError is raised trying to register a class that is
|
# Check that SubclassError is raised trying to register a class that is
|
||||||
# not a subclass of an allowed base:
|
# not a subclass of an allowed base:
|
||||||
raised = False
|
tstutil.raises(errors.SubclassError, r, plugin3)
|
||||||
try:
|
|
||||||
r(plugin3)
|
|
||||||
except errors.SubclassError:
|
|
||||||
raised = True
|
|
||||||
assert raised
|
|
||||||
|
|
||||||
# Check that registration works
|
# Check that registration works
|
||||||
r(plugin1)
|
r(plugin1)
|
||||||
@@ -193,12 +162,7 @@ def test_Registrar():
|
|||||||
|
|
||||||
# Check that DuplicateError is raised trying to register exact class
|
# Check that DuplicateError is raised trying to register exact class
|
||||||
# again:
|
# again:
|
||||||
raised = False
|
tstutil.raises(errors.DuplicateError, r, plugin1)
|
||||||
try:
|
|
||||||
r(plugin1)
|
|
||||||
except errors.DuplicateError:
|
|
||||||
raised = True
|
|
||||||
assert raised
|
|
||||||
|
|
||||||
# Check that OverrideError is raised trying to register class with same
|
# Check that OverrideError is raised trying to register class with same
|
||||||
# name and same base:
|
# name and same base:
|
||||||
@@ -207,12 +171,7 @@ def test_Registrar():
|
|||||||
pass
|
pass
|
||||||
class plugin1(base1_extended):
|
class plugin1(base1_extended):
|
||||||
pass
|
pass
|
||||||
raised = False
|
tstutil.raises(errors.OverrideError, r, plugin1)
|
||||||
try:
|
|
||||||
r(plugin1)
|
|
||||||
except errors.OverrideError:
|
|
||||||
raised = True
|
|
||||||
assert raised
|
|
||||||
|
|
||||||
# Check that overriding works
|
# Check that overriding works
|
||||||
r(plugin1, override=True)
|
r(plugin1, override=True)
|
||||||
@@ -223,12 +182,7 @@ def test_Registrar():
|
|||||||
|
|
||||||
# Check that MissingOverrideError is raised trying to override a name
|
# Check that MissingOverrideError is raised trying to override a name
|
||||||
# not yet registerd:
|
# not yet registerd:
|
||||||
raised = False
|
tstutil.raises(errors.MissingOverrideError, r, plugin2, override=True)
|
||||||
try:
|
|
||||||
r(plugin2, override=True)
|
|
||||||
except errors.MissingOverrideError:
|
|
||||||
raised = True
|
|
||||||
assert raised
|
|
||||||
|
|
||||||
# Check that additional plugin can be registered:
|
# Check that additional plugin can be registered:
|
||||||
r(plugin2)
|
r(plugin2)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class Prop(object):
|
|||||||
|
|
||||||
|
|
||||||
def test_yes_raised():
|
def test_yes_raised():
|
||||||
f = tstutil.yes_raises
|
f = tstutil.raises
|
||||||
|
|
||||||
class SomeError(Exception):
|
class SomeError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class ExceptionNotRaised(Exception):
|
|||||||
return self.msg % self.expected.__name__
|
return self.msg % self.expected.__name__
|
||||||
|
|
||||||
|
|
||||||
def yes_raises(exception, callback, *args, **kw):
|
def raises(exception, callback, *args, **kw):
|
||||||
"""
|
"""
|
||||||
Tests that the expected exception is raised; raises ExceptionNotRaised
|
Tests that the expected exception is raised; raises ExceptionNotRaised
|
||||||
if test fails.
|
if test fails.
|
||||||
@@ -53,14 +53,14 @@ def no_set(obj, name, value='some_new_obj'):
|
|||||||
"""
|
"""
|
||||||
Tests that attribute cannot be set.
|
Tests that attribute cannot be set.
|
||||||
"""
|
"""
|
||||||
yes_raises(AttributeError, setattr, obj, name, value)
|
raises(AttributeError, setattr, obj, name, value)
|
||||||
|
|
||||||
|
|
||||||
def no_del(obj, name):
|
def no_del(obj, name):
|
||||||
"""
|
"""
|
||||||
Tests that attribute cannot be deleted.
|
Tests that attribute cannot be deleted.
|
||||||
"""
|
"""
|
||||||
yes_raises(AttributeError, delattr, obj, name)
|
raises(AttributeError, delattr, obj, name)
|
||||||
|
|
||||||
|
|
||||||
def read_only(obj, name, value='some_new_obj'):
|
def read_only(obj, name, value='some_new_obj'):
|
||||||
|
|||||||
Reference in New Issue
Block a user