From a48a3b42dd78c0201010ed737fdc45244a526648 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 20 Apr 2006 16:07:39 +0000 Subject: Fix test failures for repr.py. But shouldn't we kill this module? How many pprint clones do we need? --- Lib/repr.py | 15 +++++---------- Lib/test/test_repr.py | 11 +++++------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Lib/repr.py b/Lib/repr.py index 53b5207..32544a2 100644 --- a/Lib/repr.py +++ b/Lib/repr.py @@ -18,7 +18,7 @@ class Repr: self.maxdeque = 6 self.maxstring = 30 self.maxlong = 40 - self.maxother = 20 + self.maxother = 30 def repr(self, x): return self.repr1(x, self.maxlevel) @@ -31,12 +31,7 @@ class Repr: if hasattr(self, 'repr_' + typename): return getattr(self, 'repr_' + typename)(x, level) else: - s = __builtin__.repr(x) - if len(s) > self.maxother: - i = max(0, (self.maxother-3)//2) - j = max(0, self.maxother-3-i) - s = s[:i] + '...' + s[len(s)-j:] - return s + return self.repr_instance(x, level) def _repr_iterable(self, x, level, left, right, maxiter, trail=''): n = len(x) @@ -112,9 +107,9 @@ class Repr: # exceptions -- then make up something except: return '<%s instance at %x>' % (x.__class__.__name__, id(x)) - if len(s) > self.maxstring: - i = max(0, (self.maxstring-3)//2) - j = max(0, self.maxstring-3-i) + if len(s) > self.maxother: + i = max(0, (self.maxother-3)//2) + j = max(0, self.maxother-3-i) s = s[:i] + '...' + s[len(s)-j:] return s diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py index 4ded484..9128585 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -111,7 +111,7 @@ class ReprTests(unittest.TestCase): s = r(ClassWithFailingRepr) self.failUnless(s.startswith("")) - self.failUnless(s.find("...") == 8) + self.failUnless(s.find("...") in [12, 13]) def test_file(self): fp = open(unittest.__file__) @@ -249,8 +249,7 @@ class bar: ''') from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar # Module name may be prefixed with "test.", depending on how run. - self.failUnless(repr(bar.bar).startswith( - "" % bar.__name__) def test_instance(self): touch(os.path.join(self.subpkgname, 'baz'+os.extsep+'py'), '''\ @@ -260,7 +259,7 @@ class baz: from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz ibaz = baz.baz() self.failUnless(repr(ibaz).startswith( - "<%s.baz instance at 0x" % baz.__name__)) + "<%s.baz object at 0x" % baz.__name__)) def test_method(self): eq = self.assertEquals @@ -275,7 +274,7 @@ class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # Bound method next iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() self.failUnless(repr(iqux.amethod).startswith( - '