diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-05 11:27:52 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-05 11:27:52 (GMT) |
commit | 2034d9a996b6a970992817176bab43d253248e9d (patch) | |
tree | 4e4df4e1581f766bc415f9fc9d8f55bbe0eeb436 /Lib/unittest/case.py | |
parent | 4107d31db6a0a0ce4f720ec1f6a8f62f72f5b1ce (diff) | |
download | cpython-2034d9a996b6a970992817176bab43d253248e9d.zip cpython-2034d9a996b6a970992817176bab43d253248e9d.tar.gz cpython-2034d9a996b6a970992817176bab43d253248e9d.tar.bz2 |
Merged revisions 81728 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81728 | michael.foord | 2010-06-05 12:23:51 +0100 (Sat, 05 Jun 2010) | 1 line
Issue 8351. Suppress large diffs in unittest.TestCase.assertSequenceEqual.
........
Diffstat (limited to 'Lib/unittest/case.py')
-rw-r--r-- | Lib/unittest/case.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index a072cf1..4a13f0a 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -12,7 +12,7 @@ from .util import (strclass, safe_repr, sorted_list_difference, unorderable_list_difference) __unittest = True - +TRUNCATED_DIFF = '\n[diff truncated...]' class SkipTest(Exception): """ @@ -599,7 +599,8 @@ class TestCase(object): failUnlessRaises = _deprecate(assertRaises) failIf = _deprecate(assertFalse) - def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None): + def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None, + max_diff=80*8): """An equality assertion for ordered sequences (like lists and tuples). For the purposes of this function, a valid ordered sequence type is one @@ -612,6 +613,7 @@ class TestCase(object): datatype should be enforced. msg: Optional message to use on failure instead of a list of differences. + max_diff: Maximum size off the diff, larger diffs are not shown """ if seq_type != None: seq_type_name = seq_type.__name__ @@ -694,9 +696,14 @@ 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( + standardMsg = differing + diffMsg = '\n' + '\n'.join( difflib.ndiff(pprint.pformat(seq1).splitlines(), pprint.pformat(seq2).splitlines())) + if max_diff is None or len(diffMsg) <= max_diff: + standardMsg += diffMsg + else: + standardMsg += diffMsg[:max_diff] + TRUNCATED_DIFF msg = self._formatMessage(msg, standardMsg) self.fail(msg) |