summaryrefslogtreecommitdiff
path: root/Lib/unittest/case.py
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 11:23:51 +0000
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 11:23:51 +0000
commit0100702b9a77000c03934208e9131ef5914dcf63 (patch)
tree072f02ba20bf1a7df0f2c57379c3e19916af554c /Lib/unittest/case.py
parent9ef5d33084f72ed209ec59a9ea4b0a1d968ee8d6 (diff)
downloadcpython-git-0100702b9a77000c03934208e9131ef5914dcf63.tar.gz
Issue 8351. Suppress large diffs in unittest.TestCase.assertSequenceEqual.
Diffstat (limited to 'Lib/unittest/case.py')
-rw-r--r--Lib/unittest/case.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 5c434d9e31..7608e30139 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -13,7 +13,7 @@ from .util import (
)
__unittest = True
-
+TRUNCATED_DIFF = '\n[diff truncated...]'
class SkipTest(Exception):
"""
@@ -589,7 +589,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
@@ -602,6 +603,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 is not None:
seq_type_name = seq_type.__name__
@@ -684,9 +686,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)