mirror of
https://github.com/python/cpython.git
synced 2025-07-28 21:55:21 +00:00
Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
This commit is contained in:
parent
7ab5eb91b7
commit
f2dfef1637
4 changed files with 54 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue