summaryrefslogtreecommitdiff
path: root/testlib.py
diff options
context:
space:
mode:
authorJulien Jehannet <julien.jehannet@logilab.fr>2010-08-02 16:48:41 +0200
committerJulien Jehannet <julien.jehannet@logilab.fr>2010-08-02 16:48:41 +0200
commit1165737e5d8bea2f05f12ad42d13d69373cdb6a6 (patch)
tree16fc324c19db8e592051840b4506b025750c80ca /testlib.py
parente0832048ca922827eebad278d6aa18e920843a58 (diff)
downloadlogilab-common-1165737e5d8bea2f05f12ad42d13d69373cdb6a6.tar.gz
testlib: make our legacy assertion methods compatible with unittest2
Diffstat (limited to 'testlib.py')
-rw-r--r--testlib.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/testlib.py b/testlib.py
index cec48e1..edcdc86 100644
--- a/testlib.py
+++ b/testlib.py
@@ -1268,29 +1268,32 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART)
msg = msg or 'test was skipped'
raise InnerTestSkipped(msg)
- def assertIn(self, object, set):
+ def assertIn(self, object, set, msg=None):
"""assert <object> is in <set>
:param object: a Python Object
:param set: a Python Container
+ :param msg: custom message (String) in case of failure
"""
- self.assert_(object in set, "%s not in %s" % (object, set))
+ self.assert_(object in set, msg or "%s not in %s" % (object, set))
- def assertNotIn(self, object, set):
+ def assertNotIn(self, object, set, msg=None):
"""assert <object> is not in <set>
:param object: a Python Object
:param set: the Python container to contain <object>
+ :param msg: custom message (String) in case of failure
"""
- self.assert_(object not in set, "%s in %s" % (object, set))
+ self.assert_(object not in set, msg or "%s in %s" % (object, set))
- def assertDictEquals(self, dict1, dict2):
+ def assertDictEquals(self, dict1, dict2, msg=None):
"""compares two dicts
If the two dict differ, the first difference is shown in the error
message
:param dict1: a Python Dictionary
:param dict2: a Python Dictionary
+ :param msg: custom message (String) in case of failure
"""
dict1 = dict(dict1)
msgs = []
@@ -1304,11 +1307,12 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART)
msgs.append('missing %r key' % key)
if dict1:
msgs.append('dict2 is lacking %r' % dict1)
- if msgs:
+ if msg:
+ self.failureException(msg)
+ elif msgs:
self.fail('\n'.join(msgs))
assertDictEqual = assertDictEquals
-
def assertUnorderedIterableEquals(self, got, expected, msg=None):
"""compares two iterable and shows difference between both
@@ -1716,7 +1720,6 @@ succeeded test into", osp.join(os.getcwd(),FILE_RESTART)
:param prec: a Float describing the precision
:param msg: a String for a custom message
"""
-
if msg is None:
msg = "%r != %r" % (obj, other)
self.assert_(math.fabs(obj - other) < prec, msg)