summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 11:46:59 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 11:46:59 (GMT)
commita441287f79ac793a0fe046b85f2e5e12364c6a84 (patch)
treec1aa5e2ac3af1c3c5371718888091c1b8603cacb
parent0100702b9a77000c03934208e9131ef5914dcf63 (diff)
downloadcpython-a441287f79ac793a0fe046b85f2e5e12364c6a84.zip
cpython-a441287f79ac793a0fe046b85f2e5e12364c6a84.tar.gz
cpython-a441287f79ac793a0fe046b85f2e5e12364c6a84.tar.bz2
Extract error message truncating into a method (unittest.TestCase._truncateMessage).
-rw-r--r--Lib/unittest/case.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 7608e30..de58968 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -690,13 +690,15 @@ class TestCase(object):
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
+ standardMsg = self._truncateMessage(standardMsg, diffMsg, max_diff)
msg = self._formatMessage(msg, standardMsg)
self.fail(msg)
+ def _truncateMessage(self, message, diff, max_diff):
+ if max_diff is None or len(diff) <= max_diff:
+ return message + diff
+ return message + diff[:max_diff] + TRUNCATED_DIFF
+
def assertListEqual(self, list1, list2, msg=None):
"""A list-specific equality assertion.