summaryrefslogtreecommitdiff
path: root/Lib/test/test_unittest.py
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2009-04-05 19:19:28 +0000
committerMichael Foord <fuzzyman@voidspace.org.uk>2009-04-05 19:19:28 +0000
commitf2dfef1637706e2d103151f1d333b33fc26018b0 (patch)
tree01db417483f401d70c25256cc25f6ffd8f98a96a /Lib/test/test_unittest.py
parent7ab5eb91b7aba558ef39d7fa4ca7d3a63d4e886e (diff)
downloadcpython-git-f2dfef1637706e2d103151f1d333b33fc26018b0.tar.gz
Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
Diffstat (limited to 'Lib/test/test_unittest.py')
-rw-r--r--Lib/test/test_unittest.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py
index 38c4f8f41d..f28b1af988 100644
--- a/Lib/test/test_unittest.py
+++ b/Lib/test/test_unittest.py
@@ -2301,6 +2301,16 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
# from this TestCase instance but since its a local nothing else
# will ever notice that.
+ def testAssertIs(self):
+ thing = object()
+ self.assertIs(thing, thing)
+ self.assertRaises(self.failureException, self.assertIs, thing, object())
+
+ def testAssertIsNot(self):
+ thing = object()
+ self.assertIsNot(thing, object())
+ self.assertRaises(self.failureException, self.assertIsNot, thing, thing)
+
def testAssertIn(self):
animals = {'monkey': 'banana', 'cow': 'grass', 'seal': 'fish'}
@@ -2444,6 +2454,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
# Test that sequences of unhashable objects can be tested for sameness:
self.assertSameElements([[1, 2], [3, 4]], [[3, 4], [1, 2]])
+
self.assertSameElements([{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 1}])
self.assertRaises(self.failureException, self.assertSameElements,
[[1]], [[2]])
@@ -3016,6 +3027,18 @@ class TestLongMessage(TestCase):
"^unexpectedly None$",
"^unexpectedly None : oops$"])
+ def testAssertIs(self):
+ self.assertMessages('assertIs', (None, 'foo'),
+ ["^None is not 'foo'$", "^oops$",
+ "^None is not 'foo'$",
+ "^None is not 'foo' : oops$"])
+
+ def testAssertIsNot(self):
+ self.assertMessages('assertIsNot', (None, None),
+ ["^unexpectedly identical: None$", "^oops$",
+ "^unexpectedly identical: None$",
+ "^unexpectedly identical: None : oops$"])
+
######################################################################
## Main