summaryrefslogtreecommitdiffstats
path: root/ipalib/tests/tstutil.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-01 05:44:11 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-01 05:44:11 +0000
commit4ac7ad99d6bee9b35015d5967feed24f25506d1a (patch)
tree3abfff229f6a2464650f3e0fde47eccfda7cee7d /ipalib/tests/tstutil.py
parent8a964d02b5a7c0c8a002f05597f0d1c1aabf569c (diff)
downloadfreeipa.git-4ac7ad99d6bee9b35015d5967feed24f25506d1a.tar.gz
freeipa.git-4ac7ad99d6bee9b35015d5967feed24f25506d1a.tar.xz
freeipa.git-4ac7ad99d6bee9b35015d5967feed24f25506d1a.zip
36: Added more functionality to tests.tstutil; added corresponding tests.test_tstutil unit tests
Diffstat (limited to 'ipalib/tests/tstutil.py')
-rw-r--r--ipalib/tests/tstutil.py46
1 files changed, 30 insertions, 16 deletions
diff --git a/ipalib/tests/tstutil.py b/ipalib/tests/tstutil.py
index 1c93f138..b9c6e15d 100644
--- a/ipalib/tests/tstutil.py
+++ b/ipalib/tests/tstutil.py
@@ -21,40 +21,54 @@
Utility functions for the unit tests.
"""
+class ExceptionNotRaised(Exception):
+ """
+ Exception raised when an *expected* exception is *not* raised during a
+ unit test.
+ """
+ msg = 'expected %s'
+
+ def __init__(self, expected):
+ self.expected = expected
+
+ def __str__(self):
+ return self.msg % self.expected.__name__
-def no_set(obj, name):
+
+def yes_raises(exception, callback, *args, **kw):
"""
- Tests that attribute cannot be set.
+ Tests that the expected exception is raised; raises ExceptionNotRaised
+ if test fails.
"""
raised = False
try:
- setattr(obj, name, 'some_new_obj')
- except AttributeError:
+ callback(*args, **kw)
+ except exception:
raised = True
- assert raised
+ if not raised:
+ raise ExceptionNotRaised(exception)
+
+
+def no_set(obj, name, value='some_new_obj'):
+ """
+ Tests that attribute cannot be set.
+ """
+ yes_raises(AttributeError, setattr, obj, name, value)
def no_del(obj, name):
"""
Tests that attribute cannot be deleted.
"""
- raised = False
- try:
- delattr(obj, name)
- except AttributeError:
- raised = True
- assert raised
+ yes_raises(AttributeError, delattr, obj, name)
-def read_only(obj, name):
+def read_only(obj, name, value='some_new_obj'):
"""
Tests that attribute is read-only. Returns attribute.
"""
- assert isinstance(obj, object)
- assert hasattr(obj, name)
-
# Test that it cannot be set:
- no_set(obj, name)
+ no_set(obj, name, value)
# Test that it cannot be deleted:
no_del(obj, name)