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/unittest.py | |
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/unittest.py')
-rw-r--r-- | Lib/unittest.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py index 03a11b7..cabd857 100644 --- a/Lib/unittest.py +++ b/Lib/unittest.py @@ -346,6 +346,9 @@ class TestCase(object): longMessage = False + # If a string is longer than _diffThreshold, use normal comparison instead + # of difflib. See #11763. + _diffThreshold = 2**16 def __init__(self, methodName='runTest'): """Create an instance of the class that will use the named test @@ -955,6 +958,10 @@ class TestCase(object): 'Second argument is not a string')) if first != second: + # don't use difflib if the strings are too long + if (len(first) > self._diffThreshold or + len(second) > self._diffThreshold): + self._baseAssertEqual(first, second, msg) standardMsg = '\n' + ''.join(difflib.ndiff(first.splitlines(True), second.splitlines(True))) self.fail(self._formatMessage(msg, standardMsg)) |