summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 11:27:52 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 11:27:52 (GMT)
commit2034d9a996b6a970992817176bab43d253248e9d (patch)
tree4e4df4e1581f766bc415f9fc9d8f55bbe0eeb436 /Lib/unittest/test
parent4107d31db6a0a0ce4f720ec1f6a8f62f72f5b1ce (diff)
downloadcpython-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/test')
-rw-r--r--Lib/unittest/test/test_case.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index 08c4a7b..21dd857 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -1,3 +1,5 @@
+import difflib
+import pprint
import re
import sys
@@ -589,6 +591,23 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
self.assertRaises(self.failureException, self.assertDictEqual, [], d)
self.assertRaises(self.failureException, self.assertDictEqual, 1, 1)
+ def testAssertSequenceEqualMaxDiff(self):
+ seq1 = 'a' + 'x' * 80**2
+ seq2 = 'b' + 'x' * 80**2
+ diff = '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(),
+ pprint.pformat(seq2).splitlines()))
+ try:
+ self.assertSequenceEqual(seq1, seq2, max_diff=len(diff)/2)
+ except AssertionError as e:
+ msg = e.args[0]
+ self.assertTrue(len(msg) < len(diff))
+
+ try:
+ self.assertSequenceEqual(seq1, seq2, max_diff=len(diff)*2)
+ except AssertionError as e:
+ msg = e.args[0]
+ self.assertTrue(len(msg) > len(diff))
+
def testAssertItemsEqual(self):
a = object()
self.assertItemsEqual([1, 2, 3], [3, 2, 1])