diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2009-04-05 19:19:28 +0000 |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2009-04-05 19:19:28 +0000 |
commit | f2dfef1637706e2d103151f1d333b33fc26018b0 (patch) | |
tree | 01db417483f401d70c25256cc25f6ffd8f98a96a /Lib/unittest.py | |
parent | 7ab5eb91b7aba558ef39d7fa4ca7d3a63d4e886e (diff) | |
download | cpython-git-f2dfef1637706e2d103151f1d333b33fc26018b0.tar.gz |
Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
Diffstat (limited to 'Lib/unittest.py')
-rw-r--r-- | Lib/unittest.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py index 83790fce70..f99f958d91 100644 --- a/Lib/unittest.py +++ b/Lib/unittest.py @@ -806,6 +806,18 @@ class TestCase(object): standardMsg = '%r unexpectedly found in %r' % (member, container) self.fail(self._formatMessage(msg, standardMsg)) + def assertIs(self, expr1, expr2, msg=None): + """Just like self.assertTrue(a is b), but with a nicer default message.""" + if expr1 is not expr2: + standardMsg = '%r is not %r' % (expr1, expr2) + self.fail(self._formatMessage(msg, standardMsg)) + + def assertIsNot(self, expr1, expr2, msg=None): + """Just like self.assertTrue(a is not b), but with a nicer default message.""" + if expr1 is expr2: + standardMsg = 'unexpectedly identical: %r' % (expr1,) + self.fail(self._formatMessage(msg, standardMsg)) + def assertDictEqual(self, d1, d2, msg=None): self.assert_(isinstance(d1, dict), 'First argument is not a dictionary') self.assert_(isinstance(d2, dict), 'Second argument is not a dictionary') |