From 0bcf6d8d5436e9223f795a2040e330f43ebc1ce6 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 24 Aug 2001 18:37:32 +0000 Subject: [PATCH] Added lots of tests for reprs of "simple" objects, such as file, lambda (anonymous functions?), function, xrange, buffer, cell (need to fill in), and (some) descriptor types. Also added a new test case for testing repr truncation fixes. --- Lib/test/test_repr.py | 156 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py index cf423f96b7..1281b1f276 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -3,7 +3,10 @@ Nick Mathewson """ +import sys +import os import unittest + from test_support import run_unittest from repr import repr as r # Don't shadow builtin repr @@ -75,6 +78,38 @@ class ReprTests(unittest.TestCase): i3 = ClassWithFailingRepr() eq(r(i3), (""%id(i3))) + def test_file(self): + fp = open(unittest.__file__) + self.failUnless(repr(fp).startswith( + " at 0x")) + # XXX anonymous functions? see func_repr + + def test_builtin_function(self): + eq = self.assertEquals + # Functions + eq(repr(hash), '') + # Methods + self.failUnless(repr(''.split).startswith( + '") + # XXX member descriptors + # XXX attribute descriptors + # XXX slot descriptors + # static and class methods + class C: + def foo(cls): pass + x = staticmethod(C.foo) + self.failUnless(repr(x).startswith('" % areallylongpackageandmodulenametotestreprtruncation.__file__) + + def test_type(self): + eq = self.assertEquals + touch(os.path.join(self.subpkgname, 'foo.py'), '''\ +class foo(object): + pass +''') + from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo + eq(repr(foo.foo), + "") + + def test_object(self): + # XXX Test the repr of a type with a really long tp_name but with no + # tp_repr. WIBNI we had ::Inline? :) + pass + + def test_class(self): + touch(os.path.join(self.subpkgname, 'bar.py'), '''\ +class bar: + pass +''') + from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar + self.failUnless(repr(bar.bar).startswith( + "') + # Bound method next + iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() + self.failUnless(repr(iqux.amethod).startswith( + '