blob: 3e1e8904545e24355781c6d09c1211bb06f42119 [file] [log] [blame]
Fred Drake8e6669a2001-07-19 22:27:56 +00001"""
2 Test cases for the repr module
3 Nick Mathewson
4"""
5
Barry Warsaw0bcf6d82001-08-24 18:37:32 +00006import sys
7import os
Neal Norwitz008b8612006-05-30 07:21:10 +00008import shutil
Fred Drake8e6669a2001-07-19 22:27:56 +00009import unittest
Barry Warsaw0bcf6d82001-08-24 18:37:32 +000010
Ezio Melottid80b4bf2010-03-17 13:52:48 +000011from test.test_support import run_unittest, check_py3k_warnings
Brett Cannon2ee0e8e2008-05-23 05:03:59 +000012from repr import repr as r # Don't shadow builtin repr
13from repr import Repr
Fred Drake8e6669a2001-07-19 22:27:56 +000014
15
16def nestedTuple(nesting):
17 t = ()
18 for i in range(nesting):
19 t = (t,)
20 return t
21
22class ReprTests(unittest.TestCase):
23
24 def test_string(self):
Ezio Melotti2623a372010-11-21 13:34:58 +000025 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +000026 eq(r("abc"), "'abc'")
27 eq(r("abcdefghijklmnop"),"'abcdefghijklmnop'")
28
29 s = "a"*30+"b"*30
Walter Dörwald70a6b492004-02-12 17:35:32 +000030 expected = repr(s)[:13] + "..." + repr(s)[-14:]
Fred Drake8e6669a2001-07-19 22:27:56 +000031 eq(r(s), expected)
Tim Petersab9ba272001-08-09 21:40:30 +000032
Fred Drake8e6669a2001-07-19 22:27:56 +000033 eq(r("\"'"), repr("\"'"))
34 s = "\""*30+"'"*100
Walter Dörwald70a6b492004-02-12 17:35:32 +000035 expected = repr(s)[:13] + "..." + repr(s)[-14:]
Fred Drake8e6669a2001-07-19 22:27:56 +000036 eq(r(s), expected)
37
Neal Norwitzc161cb92007-06-11 07:29:43 +000038 def test_tuple(self):
Ezio Melotti2623a372010-11-21 13:34:58 +000039 eq = self.assertEqual
Neal Norwitzc161cb92007-06-11 07:29:43 +000040 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 Drake8e6669a2001-07-19 22:27:56 +000050 def test_container(self):
Tim Peters6ee04802003-02-05 18:29:34 +000051 from array import array
Raymond Hettinger1453e4a2004-05-21 23:01:18 +000052 from collections import deque
Tim Peters6ee04802003-02-05 18:29:34 +000053
Ezio Melotti2623a372010-11-21 13:34:58 +000054 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +000055 # 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 Hettingerba6cd362004-05-21 10:00:15 +000069 # 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 Hettinger1453e4a2004-05-21 23:01:18 +000083 # collections.deque after 6
84 eq(r(deque([1, 2, 3, 4, 5, 6, 7])), "deque([1, 2, 3, 4, 5, 6, ...])")
85
Fred Drake8e6669a2001-07-19 22:27:56 +000086 # 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 Peters6ee04802003-02-05 18:29:34 +000093 # 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 Drake8e6669a2001-07-19 22:27:56 +0000103 def test_numbers(self):
Ezio Melotti2623a372010-11-21 13:34:58 +0000104 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +0000105 eq(r(123), repr(123))
106 eq(r(123L), repr(123L))
107 eq(r(1.0/3), repr(1.0/3))
108
109 n = 10L**100
Walter Dörwald70a6b492004-02-12 17:35:32 +0000110 expected = repr(n)[:18] + "..." + repr(n)[-19:]
Fred Drake8e6669a2001-07-19 22:27:56 +0000111 eq(r(n), expected)
112
113 def test_instance(self):
Ezio Melotti2623a372010-11-21 13:34:58 +0000114 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +0000115 i1 = ClassWithRepr("a")
116 eq(r(i1), repr(i1))
Tim Petersab9ba272001-08-09 21:40:30 +0000117
Fred Drake8e6669a2001-07-19 22:27:56 +0000118 i2 = ClassWithRepr("x"*1000)
Walter Dörwald70a6b492004-02-12 17:35:32 +0000119 expected = repr(i2)[:13] + "..." + repr(i2)[-14:]
Fred Drake8e6669a2001-07-19 22:27:56 +0000120 eq(r(i2), expected)
121
122 i3 = ClassWithFailingRepr()
123 eq(r(i3), ("<ClassWithFailingRepr instance at %x>"%id(i3)))
124
Guido van Rossumcf856f92001-09-05 02:26:26 +0000125 s = r(ClassWithFailingRepr)
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000126 self.assertTrue(s.startswith("<class "))
127 self.assertTrue(s.endswith(">"))
128 self.assertTrue(s.find("...") == 8)
Guido van Rossumcf856f92001-09-05 02:26:26 +0000129
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000130 def test_file(self):
131 fp = open(unittest.__file__)
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000132 self.assertTrue(repr(fp).startswith(
Ezio Melottib60156e2012-03-12 02:09:02 +0200133 "<open file %r, mode 'r' at 0x" % unittest.__file__))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000134 fp.close()
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000135 self.assertTrue(repr(fp).startswith(
Ezio Melottib60156e2012-03-12 02:09:02 +0200136 "<closed file %r, mode 'r' at 0x" % unittest.__file__))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000137
138 def test_lambda(self):
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000139 self.assertTrue(repr(lambda x: x).startswith(
Neil Schemenauerab541bb2005-10-21 18:11:40 +0000140 "<function <lambda"))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000141 # XXX anonymous functions? see func_repr
142
143 def test_builtin_function(self):
Ezio Melotti2623a372010-11-21 13:34:58 +0000144 eq = self.assertEqual
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000145 # Functions
146 eq(repr(hash), '<built-in function hash>')
147 # Methods
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000148 self.assertTrue(repr(''.split).startswith(
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000149 '<built-in method split of str object at 0x'))
150
151 def test_xrange(self):
Ezio Melotti2623a372010-11-21 13:34:58 +0000152 eq = self.assertEqual
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000153 eq(repr(xrange(1)), 'xrange(1)')
154 eq(repr(xrange(1, 2)), 'xrange(1, 2)')
155 eq(repr(xrange(1, 2, 3)), 'xrange(1, 4, 3)')
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000156
Fred Drake8e6669a2001-07-19 22:27:56 +0000157 def test_nesting(self):
Ezio Melotti2623a372010-11-21 13:34:58 +0000158 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +0000159 # everything is meant to give up after 6 levels.
160 eq(r([[[[[[[]]]]]]]), "[[[[[[[]]]]]]]")
161 eq(r([[[[[[[[]]]]]]]]), "[[[[[[[...]]]]]]]")
162
163 eq(r(nestedTuple(6)), "(((((((),),),),),),)")
164 eq(r(nestedTuple(7)), "(((((((...),),),),),),)")
165
166 eq(r({ nestedTuple(5) : nestedTuple(5) }),
167 "{((((((),),),),),): ((((((),),),),),)}")
168 eq(r({ nestedTuple(6) : nestedTuple(6) }),
169 "{((((((...),),),),),): ((((((...),),),),),)}")
170
171 eq(r([[[[[[{}]]]]]]), "[[[[[[{}]]]]]]")
172 eq(r([[[[[[[{}]]]]]]]), "[[[[[[[...]]]]]]]")
173
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000174 def test_buffer(self):
175 # XXX doesn't test buffers with no b_base or read-write buffers (see
176 # bufferobject.c). The test is fairly incomplete too. Sigh.
Ezio Melottid80b4bf2010-03-17 13:52:48 +0000177 with check_py3k_warnings():
178 x = buffer('foo')
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000179 self.assertTrue(repr(x).startswith('<read-only buffer for 0x'))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000180
181 def test_cell(self):
Serhiy Storchaka95d72192013-12-10 10:20:11 +0200182 def get_cell():
183 x = 42
184 def inner():
185 return x
186 return inner
187 x = get_cell().__closure__[0]
Zachary Ware227c01a2013-12-10 14:14:28 -0600188 self.assertRegexpMatches(repr(x), r'<cell at 0x[0-9A-Fa-f]+: '
189 r'int object at 0x[0-9A-Fa-f]+>')
Serhiy Storchaka95d72192013-12-10 10:20:11 +0200190 self.assertRegexpMatches(r(x), r'<cell at.*\.\.\..*>')
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000191
192 def test_descriptors(self):
Ezio Melotti2623a372010-11-21 13:34:58 +0000193 eq = self.assertEqual
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000194 # method descriptors
Tim Petersa427a2b2001-10-29 22:25:45 +0000195 eq(repr(dict.items), "<method 'items' of 'dict' objects>")
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000196 # XXX member descriptors
197 # XXX attribute descriptors
198 # XXX slot descriptors
199 # static and class methods
200 class C:
201 def foo(cls): pass
202 x = staticmethod(C.foo)
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000203 self.assertTrue(repr(x).startswith('<staticmethod object at 0x'))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000204 x = classmethod(C.foo)
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000205 self.assertTrue(repr(x).startswith('<classmethod object at 0x'))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000206
Georg Brandl8fd3ecf2007-09-12 19:00:07 +0000207 def test_unsortable(self):
208 # Repr.repr() used to call sorted() on sets, frozensets and dicts
209 # without taking into account that not all objects are comparable
210 x = set([1j, 2j, 3j])
211 y = frozenset(x)
212 z = {1j: 1, 2j: 2}
213 r(x)
214 r(y)
215 r(z)
216
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000217def touch(path, text=''):
218 fp = open(path, 'w')
219 fp.write(text)
220 fp.close()
221
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000222class LongReprTest(unittest.TestCase):
223 def setUp(self):
224 longname = 'areallylongpackageandmodulenametotestreprtruncation'
225 self.pkgname = os.path.join(longname)
226 self.subpkgname = os.path.join(longname, longname)
227 # Make the package and subpackage
Neal Norwitz008b8612006-05-30 07:21:10 +0000228 shutil.rmtree(self.pkgname, ignore_errors=True)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000229 os.mkdir(self.pkgname)
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000230 touch(os.path.join(self.pkgname, '__init__'+os.extsep+'py'))
Neal Norwitz008b8612006-05-30 07:21:10 +0000231 shutil.rmtree(self.subpkgname, ignore_errors=True)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000232 os.mkdir(self.subpkgname)
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000233 touch(os.path.join(self.subpkgname, '__init__'+os.extsep+'py'))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000234 # Remember where we are
235 self.here = os.getcwd()
236 sys.path.insert(0, self.here)
237
238 def tearDown(self):
239 actions = []
Benjamin Peterson9ec4aa02008-05-08 22:09:54 +0000240 for dirpath, dirnames, filenames in os.walk(self.pkgname):
241 for name in dirnames + filenames:
242 actions.append(os.path.join(dirpath, name))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000243 actions.append(self.pkgname)
244 actions.sort()
245 actions.reverse()
246 for p in actions:
247 if os.path.isdir(p):
248 os.rmdir(p)
249 else:
250 os.remove(p)
251 del sys.path[0]
252
253 def test_module(self):
Ezio Melotti2623a372010-11-21 13:34:58 +0000254 eq = self.assertEqual
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000255 touch(os.path.join(self.subpkgname, self.pkgname + os.extsep + 'py'))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000256 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation
257 eq(repr(areallylongpackageandmodulenametotestreprtruncation),
Mark Hammondd800ae12003-01-16 04:56:52 +0000258 "<module '%s' from '%s'>" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__))
Neal Norwitz70769012001-12-29 00:25:42 +0000259 eq(repr(sys), "<module 'sys' (built-in)>")
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000260
261 def test_type(self):
Ezio Melotti2623a372010-11-21 13:34:58 +0000262 eq = self.assertEqual
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000263 touch(os.path.join(self.subpkgname, 'foo'+os.extsep+'py'), '''\
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000264class foo(object):
265 pass
266''')
267 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo
268 eq(repr(foo.foo),
Mark Hammondd800ae12003-01-16 04:56:52 +0000269 "<class '%s.foo'>" % foo.__name__)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000270
Zachary Ware1f702212013-12-10 14:09:20 -0600271 @unittest.skip('need a suitable object')
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000272 def test_object(self):
273 # XXX Test the repr of a type with a really long tp_name but with no
274 # tp_repr. WIBNI we had ::Inline? :)
275 pass
276
277 def test_class(self):
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000278 touch(os.path.join(self.subpkgname, 'bar'+os.extsep+'py'), '''\
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000279class bar:
280 pass
281''')
282 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar
Mark Hammondd800ae12003-01-16 04:56:52 +0000283 # Module name may be prefixed with "test.", depending on how run.
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000284 self.assertTrue(repr(bar.bar).startswith(
Mark Hammondd800ae12003-01-16 04:56:52 +0000285 "<class %s.bar at 0x" % bar.__name__))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000286
287 def test_instance(self):
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000288 touch(os.path.join(self.subpkgname, 'baz'+os.extsep+'py'), '''\
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000289class baz:
290 pass
291''')
292 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz
293 ibaz = baz.baz()
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000294 self.assertTrue(repr(ibaz).startswith(
Mark Hammondd800ae12003-01-16 04:56:52 +0000295 "<%s.baz instance at 0x" % baz.__name__))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000296
297 def test_method(self):
Ezio Melotti2623a372010-11-21 13:34:58 +0000298 eq = self.assertEqual
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000299 touch(os.path.join(self.subpkgname, 'qux'+os.extsep+'py'), '''\
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000300class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
301 def amethod(self): pass
302''')
303 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux
304 # Unbound methods first
305 eq(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod),
306 '<unbound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod>')
307 # Bound method next
308 iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
Benjamin Peterson5c8da862009-06-30 22:57:08 +0000309 self.assertTrue(repr(iqux.amethod).startswith(
Mark Hammondd800ae12003-01-16 04:56:52 +0000310 '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa instance at 0x' \
311 % (qux.__name__,) ))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000312
Zachary Ware1f702212013-12-10 14:09:20 -0600313 @unittest.skip('needs a built-in function with a really long name')
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000314 def test_builtin_function(self):
315 # XXX test built-in functions and methods with really long names
316 pass
Fred Drake8e6669a2001-07-19 22:27:56 +0000317
318class ClassWithRepr:
319 def __init__(self, s):
320 self.s = s
321 def __repr__(self):
322 return "ClassWithLongRepr(%r)" % self.s
323
324
325class ClassWithFailingRepr:
326 def __repr__(self):
327 raise Exception("This should be caught by Repr.repr_instance")
328
329
Fred Drake2e2be372001-09-20 21:33:42 +0000330def test_main():
331 run_unittest(ReprTests)
Ronald Oussoren9545a232010-05-05 19:09:31 +0000332 run_unittest(LongReprTest)
Fred Drake2e2be372001-09-20 21:33:42 +0000333
334
335if __name__ == "__main__":
336 test_main()