Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a48a3b4

Browse files
committed
Fix test failures for repr.py.
But shouldn't we kill this module? How many pprint clones do we need?
1 parent 08a1a9f commit a48a3b4

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

Lib/repr.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self):
1818
self.maxdeque = 6
1919
self.maxstring = 30
2020
self.maxlong = 40
21-
self.maxother = 20
21+
self.maxother = 30
2222

2323
def repr(self, x):
2424
return self.repr1(x, self.maxlevel)
@@ -31,12 +31,7 @@ def repr1(self, x, level):
3131
if hasattr(self, 'repr_' + typename):
3232
return getattr(self, 'repr_' + typename)(x, level)
3333
else:
34-
s = __builtin__.repr(x)
35-
if len(s) > self.maxother:
36-
i = max(0, (self.maxother-3)//2)
37-
j = max(0, self.maxother-3-i)
38-
s = s[:i] + '...' + s[len(s)-j:]
39-
return s
34+
return self.repr_instance(x, level)
4035

4136
def _repr_iterable(self, x, level, left, right, maxiter, trail=''):
4237
n = len(x)
@@ -112,9 +107,9 @@ def repr_instance(self, x, level):
112107
# exceptions -- then make up something
113108
except:
114109
return '<%s instance at %x>' % (x.__class__.__name__, id(x))
115-
if len(s) > self.maxstring:
116-
i = max(0, (self.maxstring-3)//2)
117-
j = max(0, self.maxstring-3-i)
110+
if len(s) > self.maxother:
111+
i = max(0, (self.maxother-3)//2)
112+
j = max(0, self.maxother-3-i)
118113
s = s[:i] + '...' + s[len(s)-j:]
119114
return s
120115

Lib/test/test_repr.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_instance(self):
111111
s = r(ClassWithFailingRepr)
112112
self.failUnless(s.startswith("<class "))
113113
self.failUnless(s.endswith(">"))
114-
self.failUnless(s.find("...") == 8)
114+
self.failUnless(s.find("...") in [12, 13])
115115

116116
def test_file(self):
117117
fp = open(unittest.__file__)
@@ -249,8 +249,7 @@ class bar:
249249
''')
250250
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar
251251
# Module name may be prefixed with "test.", depending on how run.
252-
self.failUnless(repr(bar.bar).startswith(
253-
"<class %s.bar at 0x" % bar.__name__))
252+
self.assertEquals(repr(bar.bar), "<class '%s.bar'>" % bar.__name__)
254253

255254
def test_instance(self):
256255
touch(os.path.join(self.subpkgname, 'baz'+os.extsep+'py'), '''\
@@ -260,7 +259,7 @@ class baz:
260259
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz
261260
ibaz = baz.baz()
262261
self.failUnless(repr(ibaz).startswith(
263-
"<%s.baz instance at 0x" % baz.__name__))
262+
"<%s.baz object at 0x" % baz.__name__))
264263

265264
def test_method(self):
266265
eq = self.assertEquals
@@ -275,7 +274,7 @@ def amethod(self): pass
275274
# Bound method next
276275
iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
277276
self.failUnless(repr(iqux.amethod).startswith(
278-
'<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa instance at 0x' \
277+
'<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa object at 0x' \
279278
% (qux.__name__,) ))
280279

281280
def test_builtin_function(self):
@@ -286,7 +285,7 @@ class ClassWithRepr:
286285
def __init__(self, s):
287286
self.s = s
288287
def __repr__(self):
289-
return "ClassWithLongRepr(%r)" % self.s
288+
return "ClassWithRepr(%r)" % self.s
290289

291290

292291
class ClassWithFailingRepr:

0 commit comments

Comments
 (0)