summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Yves David <pierre-yves.david@logilab.fr>2008-06-19 14:55:12 +0200
committerPierre-Yves David <pierre-yves.david@logilab.fr>2008-06-19 14:55:12 +0200
commit0f2c765cd1833b756ca9426c0d6ed2b0260324c9 (patch)
tree211607f10016fc21f3d961caa2d5c8b8a2a6644e
parent5859ce5c86f4db5788b3b5a4b268173cf21c7590 (diff)
downloadlogilab-common-0f2c765cd1833b756ca9426c0d6ed2b0260324c9.tar.gz
add assertIsNot, assertNone and assertNotNone assertion
-rw-r--r--test/unittest_testlib.py14
-rw-r--r--testlib.py21
2 files changed, 34 insertions, 1 deletions
diff --git a/test/unittest_testlib.py b/test/unittest_testlib.py
index 3efaae6..e140823 100644
--- a/test/unittest_testlib.py
+++ b/test/unittest_testlib.py
@@ -213,6 +213,20 @@ class TestlibTC(TestCase):
obj_2 = []
self.assertIs(obj_1,obj_1)
self.assertRaises(AssertionError, self.assertIs, obj_1, obj_2)
+
+ def test_isnot(self):
+ obj_1 = []
+ obj_2 = []
+ self.assertIsNot(obj_1,obj_2)
+ self.assertRaises(AssertionError, self.assertIsNot, obj_1, obj_1)
+
+ def test_none(self):
+ self.assertNone(None)
+ self.assertRaises(AssertionError, self.assertNone, object())
+
+ def test_none(self):
+ self.assertNotNone(object())
+ self.assertRaises(AssertionError, self.assertNotNone, None)
class GenerativeTestsTC(TestCase):
diff --git a/testlib.py b/testlib.py
index bc8ea47..ae9820a 100644
--- a/testlib.py
+++ b/testlib.py
@@ -1134,7 +1134,7 @@ class TestCase(unittest.TestCase):
assertDictEqual = assertDictEquals
def assertSetEquals(self, got, expected, msg=None):
- """compares two iterables and shows difference between both"""
+ """compares two set and shows difference between both"""
got, expected = list(got), list(expected)
if msg is None:
msg1 = '%s != %s' % (got, expected)
@@ -1296,7 +1296,26 @@ class TestCase(unittest.TestCase):
if msg is None:
msg = "%r is not %r"%(obj, other)
self.assert_(obj is other, msg)
+
+
+ def assertIsNot(self, obj, other, msg=None):
+ """compares identity of two reference"""
+ if msg is None:
+ msg = "%r is %r"%(obj, other)
+ self.assert_(obj is not other, msg )
+ def assertNone(self, obj, msg=None):
+ """assert obj is None"""
+ if msg is None:
+ msg = "param is not None"
+ self.assert_( obj is None, msg )
+
+ def assertNotNone(self, obj, msg=None):
+ """assert obj is not None"""
+ if msg is None:
+ msg = "param is None"
+ self.assert_( obj is not None, msg )
+
def failUnlessRaises(self, excClass, callableObj, *args, **kwargs):
"""override default failUnlessRaise method to return the raised
exception instance.