Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test cases for the repr module |
| 3 | Nick Mathewson |
| 4 | """ |
| 5 | |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 6 | import sys |
| 7 | import os |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 8 | import shutil |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 9 | import unittest |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 10 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 11 | from test.support import run_unittest |
Alexandre Vassalotti | 1f2ba4b | 2008-05-16 07:12:44 +0000 | [diff] [blame] | 12 | from reprlib import repr as r # Don't shadow builtin repr |
| 13 | from reprlib import Repr |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | def nestedTuple(nesting): |
| 17 | t = () |
| 18 | for i in range(nesting): |
| 19 | t = (t,) |
| 20 | return t |
| 21 | |
| 22 | class ReprTests(unittest.TestCase): |
| 23 | |
| 24 | def test_string(self): |
| 25 | eq = self.assertEquals |
| 26 | eq(r("abc"), "'abc'") |
| 27 | eq(r("abcdefghijklmnop"),"'abcdefghijklmnop'") |
| 28 | |
| 29 | s = "a"*30+"b"*30 |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 30 | expected = repr(s)[:13] + "..." + repr(s)[-14:] |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 31 | eq(r(s), expected) |
Tim Peters | ab9ba27 | 2001-08-09 21:40:30 +0000 | [diff] [blame] | 32 | |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 33 | eq(r("\"'"), repr("\"'")) |
| 34 | s = "\""*30+"'"*100 |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 35 | expected = repr(s)[:13] + "..." + repr(s)[-14:] |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 36 | eq(r(s), expected) |
| 37 | |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 38 | def test_tuple(self): |
| 39 | eq = self.assertEquals |
| 40 | eq(r((1,)), "(1,)") |
| 41 | |
| 42 | t3 = (1, 2, 3) |
| 43 | eq(r(t3), "(1, 2, 3)") |
| 44 | |
| 45 | r2 = Repr() |
| 46 | r2.maxtuple = 2 |
| 47 | expected = repr(t3)[:-2] + "...)" |
| 48 | eq(r2.repr(t3), expected) |
| 49 | |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 50 | def test_container(self): |
Tim Peters | 6ee0480 | 2003-02-05 18:29:34 +0000 | [diff] [blame] | 51 | from array import array |
Raymond Hettinger | 1453e4a | 2004-05-21 23:01:18 +0000 | [diff] [blame] | 52 | from collections import deque |
Tim Peters | 6ee0480 | 2003-02-05 18:29:34 +0000 | [diff] [blame] | 53 | |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 54 | eq = self.assertEquals |
| 55 | # Tuples give up after 6 elements |
| 56 | eq(r(()), "()") |
| 57 | eq(r((1,)), "(1,)") |
| 58 | eq(r((1, 2, 3)), "(1, 2, 3)") |
| 59 | eq(r((1, 2, 3, 4, 5, 6)), "(1, 2, 3, 4, 5, 6)") |
| 60 | eq(r((1, 2, 3, 4, 5, 6, 7)), "(1, 2, 3, 4, 5, 6, ...)") |
| 61 | |
| 62 | # Lists give up after 6 as well |
| 63 | eq(r([]), "[]") |
| 64 | eq(r([1]), "[1]") |
| 65 | eq(r([1, 2, 3]), "[1, 2, 3]") |
| 66 | eq(r([1, 2, 3, 4, 5, 6]), "[1, 2, 3, 4, 5, 6]") |
| 67 | eq(r([1, 2, 3, 4, 5, 6, 7]), "[1, 2, 3, 4, 5, 6, ...]") |
| 68 | |
Raymond Hettinger | ba6cd36 | 2004-05-21 10:00:15 +0000 | [diff] [blame] | 69 | # Sets give up after 6 as well |
| 70 | eq(r(set([])), "set([])") |
| 71 | eq(r(set([1])), "set([1])") |
| 72 | eq(r(set([1, 2, 3])), "set([1, 2, 3])") |
| 73 | eq(r(set([1, 2, 3, 4, 5, 6])), "set([1, 2, 3, 4, 5, 6])") |
| 74 | eq(r(set([1, 2, 3, 4, 5, 6, 7])), "set([1, 2, 3, 4, 5, 6, ...])") |
| 75 | |
| 76 | # Frozensets give up after 6 as well |
| 77 | eq(r(frozenset([])), "frozenset([])") |
| 78 | eq(r(frozenset([1])), "frozenset([1])") |
| 79 | eq(r(frozenset([1, 2, 3])), "frozenset([1, 2, 3])") |
| 80 | eq(r(frozenset([1, 2, 3, 4, 5, 6])), "frozenset([1, 2, 3, 4, 5, 6])") |
| 81 | eq(r(frozenset([1, 2, 3, 4, 5, 6, 7])), "frozenset([1, 2, 3, 4, 5, 6, ...])") |
| 82 | |
Raymond Hettinger | 1453e4a | 2004-05-21 23:01:18 +0000 | [diff] [blame] | 83 | # collections.deque after 6 |
| 84 | eq(r(deque([1, 2, 3, 4, 5, 6, 7])), "deque([1, 2, 3, 4, 5, 6, ...])") |
| 85 | |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 86 | # Dictionaries give up after 4. |
| 87 | eq(r({}), "{}") |
| 88 | d = {'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4} |
| 89 | eq(r(d), "{'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4}") |
| 90 | d['arthur'] = 1 |
| 91 | eq(r(d), "{'alice': 1, 'arthur': 1, 'bob': 2, 'charles': 3, ...}") |
| 92 | |
Tim Peters | 6ee0480 | 2003-02-05 18:29:34 +0000 | [diff] [blame] | 93 | # array.array after 5. |
| 94 | eq(r(array('i')), "array('i', [])") |
| 95 | eq(r(array('i', [1])), "array('i', [1])") |
| 96 | eq(r(array('i', [1, 2])), "array('i', [1, 2])") |
| 97 | eq(r(array('i', [1, 2, 3])), "array('i', [1, 2, 3])") |
| 98 | eq(r(array('i', [1, 2, 3, 4])), "array('i', [1, 2, 3, 4])") |
| 99 | eq(r(array('i', [1, 2, 3, 4, 5])), "array('i', [1, 2, 3, 4, 5])") |
| 100 | eq(r(array('i', [1, 2, 3, 4, 5, 6])), |
| 101 | "array('i', [1, 2, 3, 4, 5, ...])") |
| 102 | |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 103 | def test_numbers(self): |
| 104 | eq = self.assertEquals |
| 105 | eq(r(123), repr(123)) |
Guido van Rossum | e2a383d | 2007-01-15 16:59:06 +0000 | [diff] [blame] | 106 | eq(r(123), repr(123)) |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 107 | eq(r(1.0/3), repr(1.0/3)) |
| 108 | |
Guido van Rossum | e2a383d | 2007-01-15 16:59:06 +0000 | [diff] [blame] | 109 | n = 10**100 |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 110 | expected = repr(n)[:18] + "..." + repr(n)[-19:] |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 111 | eq(r(n), expected) |
| 112 | |
| 113 | def test_instance(self): |
| 114 | eq = self.assertEquals |
| 115 | i1 = ClassWithRepr("a") |
| 116 | eq(r(i1), repr(i1)) |
Tim Peters | ab9ba27 | 2001-08-09 21:40:30 +0000 | [diff] [blame] | 117 | |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 118 | i2 = ClassWithRepr("x"*1000) |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 119 | expected = repr(i2)[:13] + "..." + repr(i2)[-14:] |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 120 | eq(r(i2), expected) |
| 121 | |
| 122 | i3 = ClassWithFailingRepr() |
| 123 | eq(r(i3), ("<ClassWithFailingRepr instance at %x>"%id(i3))) |
| 124 | |
Guido van Rossum | cf856f9 | 2001-09-05 02:26:26 +0000 | [diff] [blame] | 125 | s = r(ClassWithFailingRepr) |
| 126 | self.failUnless(s.startswith("<class ")) |
| 127 | self.failUnless(s.endswith(">")) |
Guido van Rossum | a48a3b4 | 2006-04-20 16:07:39 +0000 | [diff] [blame] | 128 | self.failUnless(s.find("...") in [12, 13]) |
Guido van Rossum | cf856f9 | 2001-09-05 02:26:26 +0000 | [diff] [blame] | 129 | |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 130 | def test_lambda(self): |
| 131 | self.failUnless(repr(lambda x: x).startswith( |
Neil Schemenauer | ab541bb | 2005-10-21 18:11:40 +0000 | [diff] [blame] | 132 | "<function <lambda")) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 133 | # XXX anonymous functions? see func_repr |
| 134 | |
| 135 | def test_builtin_function(self): |
| 136 | eq = self.assertEquals |
| 137 | # Functions |
| 138 | eq(repr(hash), '<built-in function hash>') |
| 139 | # Methods |
| 140 | self.failUnless(repr(''.split).startswith( |
| 141 | '<built-in method split of str object at 0x')) |
| 142 | |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 143 | def test_range(self): |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 144 | eq = self.assertEquals |
Guido van Rossum | 3353a2e | 2007-05-21 18:14:54 +0000 | [diff] [blame] | 145 | eq(repr(range(1)), 'range(0, 1)') |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 146 | eq(repr(range(1, 2)), 'range(1, 2)') |
| 147 | eq(repr(range(1, 4, 3)), 'range(1, 4, 3)') |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 148 | |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 149 | def test_nesting(self): |
| 150 | eq = self.assertEquals |
| 151 | # everything is meant to give up after 6 levels. |
| 152 | eq(r([[[[[[[]]]]]]]), "[[[[[[[]]]]]]]") |
| 153 | eq(r([[[[[[[[]]]]]]]]), "[[[[[[[...]]]]]]]") |
| 154 | |
| 155 | eq(r(nestedTuple(6)), "(((((((),),),),),),)") |
| 156 | eq(r(nestedTuple(7)), "(((((((...),),),),),),)") |
| 157 | |
| 158 | eq(r({ nestedTuple(5) : nestedTuple(5) }), |
| 159 | "{((((((),),),),),): ((((((),),),),),)}") |
| 160 | eq(r({ nestedTuple(6) : nestedTuple(6) }), |
| 161 | "{((((((...),),),),),): ((((((...),),),),),)}") |
| 162 | |
| 163 | eq(r([[[[[[{}]]]]]]), "[[[[[[{}]]]]]]") |
| 164 | eq(r([[[[[[[{}]]]]]]]), "[[[[[[[...]]]]]]]") |
| 165 | |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 166 | def test_cell(self): |
| 167 | # XXX Hmm? How to get at a cell object? |
| 168 | pass |
| 169 | |
| 170 | def test_descriptors(self): |
| 171 | eq = self.assertEquals |
| 172 | # method descriptors |
Tim Peters | a427a2b | 2001-10-29 22:25:45 +0000 | [diff] [blame] | 173 | eq(repr(dict.items), "<method 'items' of 'dict' objects>") |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 174 | # XXX member descriptors |
| 175 | # XXX attribute descriptors |
| 176 | # XXX slot descriptors |
| 177 | # static and class methods |
| 178 | class C: |
| 179 | def foo(cls): pass |
| 180 | x = staticmethod(C.foo) |
| 181 | self.failUnless(repr(x).startswith('<staticmethod object at 0x')) |
| 182 | x = classmethod(C.foo) |
| 183 | self.failUnless(repr(x).startswith('<classmethod object at 0x')) |
| 184 | |
Thomas Wouters | 1b7f891 | 2007-09-19 03:06:30 +0000 | [diff] [blame] | 185 | def test_unsortable(self): |
| 186 | # Repr.repr() used to call sorted() on sets, frozensets and dicts |
| 187 | # without taking into account that not all objects are comparable |
| 188 | x = set([1j, 2j, 3j]) |
| 189 | y = frozenset(x) |
| 190 | z = {1j: 1, 2j: 2} |
| 191 | r(x) |
| 192 | r(y) |
| 193 | r(z) |
| 194 | |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 195 | def touch(path, text=''): |
| 196 | fp = open(path, 'w') |
| 197 | fp.write(text) |
| 198 | fp.close() |
| 199 | |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 200 | class LongReprTest(unittest.TestCase): |
| 201 | def setUp(self): |
| 202 | longname = 'areallylongpackageandmodulenametotestreprtruncation' |
| 203 | self.pkgname = os.path.join(longname) |
| 204 | self.subpkgname = os.path.join(longname, longname) |
| 205 | # Make the package and subpackage |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 206 | shutil.rmtree(self.pkgname, ignore_errors=True) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 207 | os.mkdir(self.pkgname) |
Skip Montanaro | 7a98be2 | 2007-08-16 14:35:24 +0000 | [diff] [blame] | 208 | touch(os.path.join(self.pkgname, '__init__.py')) |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 209 | shutil.rmtree(self.subpkgname, ignore_errors=True) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 210 | os.mkdir(self.subpkgname) |
Skip Montanaro | 7a98be2 | 2007-08-16 14:35:24 +0000 | [diff] [blame] | 211 | touch(os.path.join(self.subpkgname, '__init__.py')) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 212 | # Remember where we are |
| 213 | self.here = os.getcwd() |
| 214 | sys.path.insert(0, self.here) |
| 215 | |
| 216 | def tearDown(self): |
| 217 | actions = [] |
Benjamin Peterson | 699adb9 | 2008-05-08 22:27:58 +0000 | [diff] [blame] | 218 | for dirpath, dirnames, filenames in os.walk(self.pkgname): |
| 219 | for name in dirnames + filenames: |
| 220 | actions.append(os.path.join(dirpath, name)) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 221 | actions.append(self.pkgname) |
| 222 | actions.sort() |
| 223 | actions.reverse() |
| 224 | for p in actions: |
| 225 | if os.path.isdir(p): |
| 226 | os.rmdir(p) |
| 227 | else: |
| 228 | os.remove(p) |
| 229 | del sys.path[0] |
| 230 | |
| 231 | def test_module(self): |
| 232 | eq = self.assertEquals |
Skip Montanaro | 7a98be2 | 2007-08-16 14:35:24 +0000 | [diff] [blame] | 233 | touch(os.path.join(self.subpkgname, self.pkgname + '.py')) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 234 | from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation |
| 235 | eq(repr(areallylongpackageandmodulenametotestreprtruncation), |
Mark Hammond | d800ae1 | 2003-01-16 04:56:52 +0000 | [diff] [blame] | 236 | "<module '%s' from '%s'>" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__)) |
Neal Norwitz | 7076901 | 2001-12-29 00:25:42 +0000 | [diff] [blame] | 237 | eq(repr(sys), "<module 'sys' (built-in)>") |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 238 | |
| 239 | def test_type(self): |
| 240 | eq = self.assertEquals |
Skip Montanaro | 7a98be2 | 2007-08-16 14:35:24 +0000 | [diff] [blame] | 241 | touch(os.path.join(self.subpkgname, 'foo.py'), '''\ |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 242 | class foo(object): |
| 243 | pass |
| 244 | ''') |
| 245 | from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo |
| 246 | eq(repr(foo.foo), |
Mark Hammond | d800ae1 | 2003-01-16 04:56:52 +0000 | [diff] [blame] | 247 | "<class '%s.foo'>" % foo.__name__) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 248 | |
| 249 | def test_object(self): |
| 250 | # XXX Test the repr of a type with a really long tp_name but with no |
| 251 | # tp_repr. WIBNI we had ::Inline? :) |
| 252 | pass |
| 253 | |
| 254 | def test_class(self): |
Skip Montanaro | 7a98be2 | 2007-08-16 14:35:24 +0000 | [diff] [blame] | 255 | touch(os.path.join(self.subpkgname, 'bar.py'), '''\ |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 256 | class bar: |
| 257 | pass |
| 258 | ''') |
| 259 | from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar |
Mark Hammond | d800ae1 | 2003-01-16 04:56:52 +0000 | [diff] [blame] | 260 | # Module name may be prefixed with "test.", depending on how run. |
Guido van Rossum | a48a3b4 | 2006-04-20 16:07:39 +0000 | [diff] [blame] | 261 | self.assertEquals(repr(bar.bar), "<class '%s.bar'>" % bar.__name__) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 262 | |
| 263 | def test_instance(self): |
Skip Montanaro | 7a98be2 | 2007-08-16 14:35:24 +0000 | [diff] [blame] | 264 | touch(os.path.join(self.subpkgname, 'baz.py'), '''\ |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 265 | class baz: |
| 266 | pass |
| 267 | ''') |
| 268 | from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz |
| 269 | ibaz = baz.baz() |
| 270 | self.failUnless(repr(ibaz).startswith( |
Guido van Rossum | a48a3b4 | 2006-04-20 16:07:39 +0000 | [diff] [blame] | 271 | "<%s.baz object at 0x" % baz.__name__)) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 272 | |
| 273 | def test_method(self): |
| 274 | eq = self.assertEquals |
Skip Montanaro | 7a98be2 | 2007-08-16 14:35:24 +0000 | [diff] [blame] | 275 | touch(os.path.join(self.subpkgname, 'qux.py'), '''\ |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 276 | class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: |
| 277 | def amethod(self): pass |
| 278 | ''') |
| 279 | from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux |
| 280 | # Unbound methods first |
Christian Heimes | 4a22b5d | 2007-11-25 09:39:14 +0000 | [diff] [blame] | 281 | self.failUnless(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod).startswith( |
| 282 | '<function amethod')) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 283 | # Bound method next |
| 284 | iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() |
| 285 | self.failUnless(repr(iqux.amethod).startswith( |
Guido van Rossum | a48a3b4 | 2006-04-20 16:07:39 +0000 | [diff] [blame] | 286 | '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa object at 0x' \ |
Mark Hammond | d800ae1 | 2003-01-16 04:56:52 +0000 | [diff] [blame] | 287 | % (qux.__name__,) )) |
Barry Warsaw | 0bcf6d8 | 2001-08-24 18:37:32 +0000 | [diff] [blame] | 288 | |
| 289 | def test_builtin_function(self): |
| 290 | # XXX test built-in functions and methods with really long names |
| 291 | pass |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 292 | |
| 293 | class ClassWithRepr: |
| 294 | def __init__(self, s): |
| 295 | self.s = s |
| 296 | def __repr__(self): |
Guido van Rossum | a48a3b4 | 2006-04-20 16:07:39 +0000 | [diff] [blame] | 297 | return "ClassWithRepr(%r)" % self.s |
Fred Drake | 8e6669a | 2001-07-19 22:27:56 +0000 | [diff] [blame] | 298 | |
| 299 | |
| 300 | class ClassWithFailingRepr: |
| 301 | def __repr__(self): |
| 302 | raise Exception("This should be caught by Repr.repr_instance") |
| 303 | |
| 304 | |
Fred Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame] | 305 | def test_main(): |
| 306 | run_unittest(ReprTests) |
| 307 | if os.name != 'mac': |
| 308 | run_unittest(LongReprTest) |
| 309 | |
| 310 | |
| 311 | if __name__ == "__main__": |
| 312 | test_main() |