diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-04-27 07:17:34 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-04-27 07:17:34 (GMT) |
commit | 935a5888255b60b77547e7bdf32e03fbe963ef52 (patch) | |
tree | 9b961df2edfd13c0df9f5eb2012c12d124282605 /Lib/test | |
parent | 72387f90fd317199ed1df1605f1d719870033355 (diff) | |
download | cpython-935a5888255b60b77547e7bdf32e03fbe963ef52.zip cpython-935a5888255b60b77547e7bdf32e03fbe963ef52.tar.gz cpython-935a5888255b60b77547e7bdf32e03fbe963ef52.tar.bz2 |
#11763: don't use difflib in TestCase.assertMultiLineEqual if the strings are too long.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_unittest.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index 21e0806..c4cad83 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -2719,6 +2719,41 @@ test case # no fair testing ourself with ourself, use assertEqual.. self.assertEqual(sample_text_error, str(e)) + def testAssertEqual_diffThreshold(self): + # check threshold value + self.assertEqual(self._diffThreshold, 2**16) + # disable madDiff to get diff markers + self.maxDiff = None + + # set a lower threshold value and add a cleanup to restore it + old_threshold = self._diffThreshold + self._diffThreshold = 2**8 + self.addCleanup(lambda: setattr(self, '_diffThreshold', old_threshold)) + + # under the threshold: diff marker (^) in error message + s = 'x' * (2**7) + try: + self.assertMultiLineEqual(s + 'a', s + 'b') + except self.failureException as exc: + err_msg = str(exc) + else: + self.fail('assertEqual unexpectedly succeeded') + self.assertIn('^', err_msg) + self.assertMultiLineEqual(s + 'a', s + 'a') + + # over the threshold: diff not used and marker (^) not in error message + s = 'x' * (2**9) + s1, s2 = s + 'a', s + 'b' + try: + self.assertMultiLineEqual(s1, s2) + except self.failureException as exc: + err_msg = str(exc) + else: + self.fail('assertEqual unexpectedly succeeded') + self.assertNotIn('^', err_msg) + self.assertEqual(err_msg, '%r != %r' % (s1, s2)) + self.assertMultiLineEqual(s + 'a', s + 'a') + def testAssertIsNone(self): self.assertIsNone(None) self.assertRaises(self.failureException, self.assertIsNone, False) |