diff options
author | Georg Brandl <georg@python.org> | 2009-10-01 20:59:31 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-10-01 20:59:31 (GMT) |
commit | f895cf5d33f68bfd750e4cce19f3785096812e34 (patch) | |
tree | 8e87952720331e39333b6c5339c10983ab8830e0 /Lib/unittest | |
parent | 46cc46af07b3d2e495117f10e591cf1dfc77608e (diff) | |
download | cpython-f895cf5d33f68bfd750e4cce19f3785096812e34.zip cpython-f895cf5d33f68bfd750e4cce19f3785096812e34.tar.gz cpython-f895cf5d33f68bfd750e4cce19f3785096812e34.tar.bz2 |
#7031: Add TestCase.assertIsInstance and negated method.
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/case.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index fb96a88..113422c 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -817,6 +817,19 @@ class TestCase(object): standardMsg = 'unexpectedly None' self.fail(self._formatMessage(msg, standardMsg)) + def assertIsInstance(self, obj, cls, msg=None): + """Same as self.assertTrue(isinstance(obj, cls)), with a nicer + default message.""" + if not isinstance(obj, cls): + standardMsg = '%r is not an instance of %r' % (obj, cls) + self.fail(self._formatMessage(msg, standardMsg)) + + def assertNotIsInstance(self, obj, cls, msg=None): + """Included for symmetry with assertIsInstance.""" + if isinstance(obj, cls): + standardMsg = '%r is an instance of %r' % (obj, cls) + self.fail(self._formatMessage(msg, standardMsg)) + def assertRaisesRegexp(self, expected_exception, expected_regexp, callable_obj=None, *args, **kwargs): """Asserts that the message in a raised exception matches a regexp. |