diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-05 12:17:02 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-05 12:17:02 (GMT) |
commit | 085dfd3ad5470050bed2f225bd4f490243ad0117 (patch) | |
tree | ae06c0e0c11884b5cdf6cf77d5b33484e81e8d38 /Lib/unittest/test | |
parent | 8f3d0fa4438ea9e638814b380a8a707315bebe3c (diff) | |
download | cpython-085dfd3ad5470050bed2f225bd4f490243ad0117.zip cpython-085dfd3ad5470050bed2f225bd4f490243ad0117.tar.gz cpython-085dfd3ad5470050bed2f225bd4f490243ad0117.tar.bz2 |
Merged revisions 81739 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81739 | michael.foord | 2010-06-05 13:10:52 +0100 (Sat, 05 Jun 2010) | 1 line
Removed the new max_diff argument to assertSequenceEqual. All unittest.TestCase assert methods that use difflib to produce failure messages now truncate overly long messages. New class attribute unittest.TestCase.maxDiff to configure this if necessary. Issue 8351.
........
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r-- | Lib/unittest/test/test_case.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index 14a386a..7de7931 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -592,20 +592,38 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): self.assertRaises(self.failureException, self.assertDictEqual, 1, 1) def testAssertSequenceEqualMaxDiff(self): + self.assertEqual(self.maxDiff, 80*8) seq1 = 'a' + 'x' * 80**2 seq2 = 'b' + 'x' * 80**2 diff = '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(), pprint.pformat(seq2).splitlines())) + + self.maxDiff = len(diff)//2 try: - self.assertSequenceEqual(seq1, seq2, max_diff=len(diff)//2) - except AssertionError as e: + + self.assertSequenceEqual(seq1, seq2) + except self.failureException as e: msg = e.args[0] + else: + self.fail('assertSequenceEqual did not fail.') self.assertTrue(len(msg) < len(diff)) + self.maxDiff = len(diff) * 2 + try: + self.assertSequenceEqual(seq1, seq2) + except self.failureException as e: + msg = e.args[0] + else: + self.fail('assertSequenceEqual did not fail.') + self.assertTrue(len(msg) > len(diff)) + + self.maxDiff = None try: - self.assertSequenceEqual(seq1, seq2, max_diff=len(diff)*2) - except AssertionError as e: + self.assertSequenceEqual(seq1, seq2) + except self.failureException as e: msg = e.args[0] + else: + self.fail('assertSequenceEqual did not fail.') self.assertTrue(len(msg) > len(diff)) def testAssertItemsEqual(self): |