diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-10-04 20:19:21 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-10-04 20:19:21 (GMT) |
commit | 6e8c75755a1bb0cd8fb79944a8617802aa0c4e44 (patch) | |
tree | 03d732d40f80da6edce6c895d0876c5add347e59 /Lib/unittest | |
parent | 23c5050b25be66646af4d8a8fc2f9338a51e226a (diff) | |
download | cpython-6e8c75755a1bb0cd8fb79944a8617802aa0c4e44.zip cpython-6e8c75755a1bb0cd8fb79944a8617802aa0c4e44.tar.gz cpython-6e8c75755a1bb0cd8fb79944a8617802aa0c4e44.tar.bz2 |
Merged revisions 74865,75175,75180 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74865 | georg.brandl | 2009-09-17 02:49:37 -0500 (Thu, 17 Sep 2009) | 1 line
#6912: add "with" block support to pindent.
........
r75175 | georg.brandl | 2009-10-01 15:11:14 -0500 (Thu, 01 Oct 2009) | 1 line
Fix some weird whitespace and two other overlong lines.
........
r75180 | georg.brandl | 2009-10-01 15:59:31 -0500 (Thu, 01 Oct 2009) | 1 line
#7031: Add TestCase.assertIsInstance and negated method.
........
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/case.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 660ddeb..88254be 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -620,8 +620,9 @@ class TestCase(object): except (TypeError, IndexError, NotImplementedError): differing += ('Unable to index element %d ' 'of second %s\n' % (len1, seq_type_name)) - standardMsg = differing + '\n' + '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(), - pprint.pformat(seq2).splitlines())) + standardMsg = differing + '\n' + '\n'.join( + difflib.ndiff(pprint.pformat(seq1).splitlines(), + pprint.pformat(seq2).splitlines())) msg = self._formatMessage(msg, standardMsg) self.fail(msg) @@ -734,7 +735,8 @@ class TestCase(object): if key not in actual: missing.append(key) elif value != actual[key]: - mismatched.append('%s, expected: %s, actual: %s' % (key, value, actual[key])) + mismatched.append('%s, expected: %s, actual: %s' % + (key, value, actual[key])) if not (missing or mismatched): return @@ -793,7 +795,8 @@ class TestCase(object): 'Second argument is not a string')) if first != second: - standardMsg = '\n' + ''.join(difflib.ndiff(first.splitlines(True), second.splitlines(True))) + standardMsg = '\n' + ''.join(difflib.ndiff(first.splitlines(True), + second.splitlines(True))) self.fail(self._formatMessage(msg, standardMsg)) def assertLess(self, a, b, msg=None): @@ -832,6 +835,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. |