summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/util.py
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 13:14:43 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 13:14:43 (GMT)
commitcb11b251a09fe141b3ded25744b70caea51f6551 (patch)
tree464430d5658a90f4e1e4bd566ac8fdd927e7c9e7 /Lib/unittest/util.py
parent02ff2100d3935bbdb9ea0000b667982aecc9d6ee (diff)
downloadcpython-cb11b251a09fe141b3ded25744b70caea51f6551.zip
cpython-cb11b251a09fe141b3ded25744b70caea51f6551.tar.gz
cpython-cb11b251a09fe141b3ded25744b70caea51f6551.tar.bz2
Merged revisions 81747 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81747 | michael.foord | 2010-06-05 13:58:39 +0100 (Sat, 05 Jun 2010) | 1 line unittest.TestCase.assertDictEqual and assertMultilineEqual provide better default failure messages in the event of long diffs. ........
Diffstat (limited to 'Lib/unittest/util.py')
-rw-r--r--Lib/unittest/util.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/unittest/util.py b/Lib/unittest/util.py
index ea8a68d..c3f4a2d 100644
--- a/Lib/unittest/util.py
+++ b/Lib/unittest/util.py
@@ -2,12 +2,16 @@
__unittest = True
-
-def safe_repr(obj):
+_MAX_LENGTH = 80
+def safe_repr(obj, short=False):
try:
- return repr(obj)
+ result = repr(obj)
except Exception:
- return object.__repr__(obj)
+ result = object.__repr__(obj)
+ if not short or len(result) < _MAX_LENGTH:
+ return result
+ return result[:_MAX_LENGTH] + ' [truncated]...'
+
def strclass(cls):
return "%s.%s" % (cls.__module__, cls.__name__)