blob: e75ba1ce90936b405672dbc55123c183024ae78f [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
Thomas Wouters4d70c3d2006-06-08 14:42:34 +00008import shutil
Antoine Pitrouc541f8e2012-02-20 01:48:16 +01009import importlib
Fred Drake8e6669a2001-07-19 22:27:56 +000010import unittest
Barry Warsaw0bcf6d82001-08-24 18:37:32 +000011
Victor Stinnerbf816222011-06-30 23:25:47 +020012from test.support import run_unittest, create_empty_file
Alexandre Vassalotti1f2ba4b2008-05-16 07:12:44 +000013from reprlib import repr as r # Don't shadow builtin repr
14from reprlib import Repr
Raymond Hettinger98a5f3f2010-09-13 21:36:00 +000015from reprlib import recursive_repr
Fred Drake8e6669a2001-07-19 22:27:56 +000016
17
18def nestedTuple(nesting):
19 t = ()
20 for i in range(nesting):
21 t = (t,)
22 return t
23
24class ReprTests(unittest.TestCase):
25
26 def test_string(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +000027 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +000028 eq(r("abc"), "'abc'")
29 eq(r("abcdefghijklmnop"),"'abcdefghijklmnop'")
30
31 s = "a"*30+"b"*30
Walter Dörwald70a6b492004-02-12 17:35:32 +000032 expected = repr(s)[:13] + "..." + repr(s)[-14:]
Fred Drake8e6669a2001-07-19 22:27:56 +000033 eq(r(s), expected)
Tim Petersab9ba272001-08-09 21:40:30 +000034
Fred Drake8e6669a2001-07-19 22:27:56 +000035 eq(r("\"'"), repr("\"'"))
36 s = "\""*30+"'"*100
Walter Dörwald70a6b492004-02-12 17:35:32 +000037 expected = repr(s)[:13] + "..." + repr(s)[-14:]
Fred Drake8e6669a2001-07-19 22:27:56 +000038 eq(r(s), expected)
39
Guido van Rossumcd16bf62007-06-13 18:07:49 +000040 def test_tuple(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +000041 eq = self.assertEqual
Guido van Rossumcd16bf62007-06-13 18:07:49 +000042 eq(r((1,)), "(1,)")
43
44 t3 = (1, 2, 3)
45 eq(r(t3), "(1, 2, 3)")
46
47 r2 = Repr()
48 r2.maxtuple = 2
49 expected = repr(t3)[:-2] + "...)"
50 eq(r2.repr(t3), expected)
51
Fred Drake8e6669a2001-07-19 22:27:56 +000052 def test_container(self):
Tim Peters6ee04802003-02-05 18:29:34 +000053 from array import array
Raymond Hettinger1453e4a2004-05-21 23:01:18 +000054 from collections import deque
Tim Peters6ee04802003-02-05 18:29:34 +000055
Ezio Melottib3aedd42010-11-20 19:04:17 +000056 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +000057 # Tuples give up after 6 elements
58 eq(r(()), "()")
59 eq(r((1,)), "(1,)")
60 eq(r((1, 2, 3)), "(1, 2, 3)")
61 eq(r((1, 2, 3, 4, 5, 6)), "(1, 2, 3, 4, 5, 6)")
62 eq(r((1, 2, 3, 4, 5, 6, 7)), "(1, 2, 3, 4, 5, 6, ...)")
63
64 # Lists give up after 6 as well
65 eq(r([]), "[]")
66 eq(r([1]), "[1]")
67 eq(r([1, 2, 3]), "[1, 2, 3]")
68 eq(r([1, 2, 3, 4, 5, 6]), "[1, 2, 3, 4, 5, 6]")
69 eq(r([1, 2, 3, 4, 5, 6, 7]), "[1, 2, 3, 4, 5, 6, ...]")
70
Raymond Hettingerba6cd362004-05-21 10:00:15 +000071 # Sets give up after 6 as well
72 eq(r(set([])), "set([])")
73 eq(r(set([1])), "set([1])")
74 eq(r(set([1, 2, 3])), "set([1, 2, 3])")
75 eq(r(set([1, 2, 3, 4, 5, 6])), "set([1, 2, 3, 4, 5, 6])")
76 eq(r(set([1, 2, 3, 4, 5, 6, 7])), "set([1, 2, 3, 4, 5, 6, ...])")
77
78 # Frozensets give up after 6 as well
79 eq(r(frozenset([])), "frozenset([])")
80 eq(r(frozenset([1])), "frozenset([1])")
81 eq(r(frozenset([1, 2, 3])), "frozenset([1, 2, 3])")
82 eq(r(frozenset([1, 2, 3, 4, 5, 6])), "frozenset([1, 2, 3, 4, 5, 6])")
83 eq(r(frozenset([1, 2, 3, 4, 5, 6, 7])), "frozenset([1, 2, 3, 4, 5, 6, ...])")
84
Raymond Hettinger1453e4a2004-05-21 23:01:18 +000085 # collections.deque after 6
86 eq(r(deque([1, 2, 3, 4, 5, 6, 7])), "deque([1, 2, 3, 4, 5, 6, ...])")
87
Fred Drake8e6669a2001-07-19 22:27:56 +000088 # Dictionaries give up after 4.
89 eq(r({}), "{}")
90 d = {'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4}
91 eq(r(d), "{'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4}")
92 d['arthur'] = 1
93 eq(r(d), "{'alice': 1, 'arthur': 1, 'bob': 2, 'charles': 3, ...}")
94
Tim Peters6ee04802003-02-05 18:29:34 +000095 # array.array after 5.
96 eq(r(array('i')), "array('i', [])")
97 eq(r(array('i', [1])), "array('i', [1])")
98 eq(r(array('i', [1, 2])), "array('i', [1, 2])")
99 eq(r(array('i', [1, 2, 3])), "array('i', [1, 2, 3])")
100 eq(r(array('i', [1, 2, 3, 4])), "array('i', [1, 2, 3, 4])")
101 eq(r(array('i', [1, 2, 3, 4, 5])), "array('i', [1, 2, 3, 4, 5])")
102 eq(r(array('i', [1, 2, 3, 4, 5, 6])),
103 "array('i', [1, 2, 3, 4, 5, ...])")
104
Fred Drake8e6669a2001-07-19 22:27:56 +0000105 def test_numbers(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000106 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +0000107 eq(r(123), repr(123))
Guido van Rossume2a383d2007-01-15 16:59:06 +0000108 eq(r(123), repr(123))
Fred Drake8e6669a2001-07-19 22:27:56 +0000109 eq(r(1.0/3), repr(1.0/3))
110
Guido van Rossume2a383d2007-01-15 16:59:06 +0000111 n = 10**100
Walter Dörwald70a6b492004-02-12 17:35:32 +0000112 expected = repr(n)[:18] + "..." + repr(n)[-19:]
Fred Drake8e6669a2001-07-19 22:27:56 +0000113 eq(r(n), expected)
114
115 def test_instance(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000116 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +0000117 i1 = ClassWithRepr("a")
118 eq(r(i1), repr(i1))
Tim Petersab9ba272001-08-09 21:40:30 +0000119
Fred Drake8e6669a2001-07-19 22:27:56 +0000120 i2 = ClassWithRepr("x"*1000)
Walter Dörwald70a6b492004-02-12 17:35:32 +0000121 expected = repr(i2)[:13] + "..." + repr(i2)[-14:]
Fred Drake8e6669a2001-07-19 22:27:56 +0000122 eq(r(i2), expected)
123
124 i3 = ClassWithFailingRepr()
125 eq(r(i3), ("<ClassWithFailingRepr instance at %x>"%id(i3)))
126
Guido van Rossumcf856f92001-09-05 02:26:26 +0000127 s = r(ClassWithFailingRepr)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000128 self.assertTrue(s.startswith("<class "))
129 self.assertTrue(s.endswith(">"))
Benjamin Peterson577473f2010-01-19 00:09:57 +0000130 self.assertIn(s.find("..."), [12, 13])
Guido van Rossumcf856f92001-09-05 02:26:26 +0000131
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000132 def test_lambda(self):
Antoine Pitrou86a36b52011-11-25 18:56:07 +0100133 r = repr(lambda x: x)
134 self.assertTrue(r.startswith("<function ReprTests.test_lambda.<locals>.<lambda"), r)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000135 # XXX anonymous functions? see func_repr
136
137 def test_builtin_function(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000138 eq = self.assertEqual
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000139 # Functions
140 eq(repr(hash), '<built-in function hash>')
141 # Methods
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000142 self.assertTrue(repr(''.split).startswith(
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000143 '<built-in method split of str object at 0x'))
144
Guido van Rossum805365e2007-05-07 22:24:25 +0000145 def test_range(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000146 eq = self.assertEqual
Guido van Rossum3353a2e2007-05-21 18:14:54 +0000147 eq(repr(range(1)), 'range(0, 1)')
Guido van Rossum805365e2007-05-07 22:24:25 +0000148 eq(repr(range(1, 2)), 'range(1, 2)')
149 eq(repr(range(1, 4, 3)), 'range(1, 4, 3)')
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000150
Fred Drake8e6669a2001-07-19 22:27:56 +0000151 def test_nesting(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000152 eq = self.assertEqual
Fred Drake8e6669a2001-07-19 22:27:56 +0000153 # everything is meant to give up after 6 levels.
154 eq(r([[[[[[[]]]]]]]), "[[[[[[[]]]]]]]")
155 eq(r([[[[[[[[]]]]]]]]), "[[[[[[[...]]]]]]]")
156
157 eq(r(nestedTuple(6)), "(((((((),),),),),),)")
158 eq(r(nestedTuple(7)), "(((((((...),),),),),),)")
159
160 eq(r({ nestedTuple(5) : nestedTuple(5) }),
161 "{((((((),),),),),): ((((((),),),),),)}")
162 eq(r({ nestedTuple(6) : nestedTuple(6) }),
163 "{((((((...),),),),),): ((((((...),),),),),)}")
164
165 eq(r([[[[[[{}]]]]]]), "[[[[[[{}]]]]]]")
166 eq(r([[[[[[[{}]]]]]]]), "[[[[[[[...]]]]]]]")
167
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000168 def test_cell(self):
169 # XXX Hmm? How to get at a cell object?
170 pass
171
172 def test_descriptors(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000173 eq = self.assertEqual
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000174 # method descriptors
Tim Petersa427a2b2001-10-29 22:25:45 +0000175 eq(repr(dict.items), "<method 'items' of 'dict' objects>")
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000176 # XXX member descriptors
177 # XXX attribute descriptors
178 # XXX slot descriptors
179 # static and class methods
180 class C:
181 def foo(cls): pass
182 x = staticmethod(C.foo)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000183 self.assertTrue(repr(x).startswith('<staticmethod object at 0x'))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000184 x = classmethod(C.foo)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000185 self.assertTrue(repr(x).startswith('<classmethod object at 0x'))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000186
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000187 def test_unsortable(self):
188 # Repr.repr() used to call sorted() on sets, frozensets and dicts
189 # without taking into account that not all objects are comparable
190 x = set([1j, 2j, 3j])
191 y = frozenset(x)
192 z = {1j: 1, 2j: 2}
193 r(x)
194 r(y)
195 r(z)
196
Victor Stinnerbf816222011-06-30 23:25:47 +0200197def write_file(path, text):
198 with open(path, 'w', encoding='ASCII') as fp:
199 fp.write(text)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000200
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000201class LongReprTest(unittest.TestCase):
202 def setUp(self):
203 longname = 'areallylongpackageandmodulenametotestreprtruncation'
204 self.pkgname = os.path.join(longname)
205 self.subpkgname = os.path.join(longname, longname)
206 # Make the package and subpackage
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000207 shutil.rmtree(self.pkgname, ignore_errors=True)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000208 os.mkdir(self.pkgname)
Victor Stinnerbf816222011-06-30 23:25:47 +0200209 create_empty_file(os.path.join(self.pkgname, '__init__.py'))
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000210 shutil.rmtree(self.subpkgname, ignore_errors=True)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000211 os.mkdir(self.subpkgname)
Victor Stinnerbf816222011-06-30 23:25:47 +0200212 create_empty_file(os.path.join(self.subpkgname, '__init__.py'))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000213 # Remember where we are
214 self.here = os.getcwd()
215 sys.path.insert(0, self.here)
Antoine Pitrouc541f8e2012-02-20 01:48:16 +0100216 importlib.invalidate_caches()
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000217
218 def tearDown(self):
219 actions = []
Benjamin Peterson699adb92008-05-08 22:27:58 +0000220 for dirpath, dirnames, filenames in os.walk(self.pkgname):
221 for name in dirnames + filenames:
222 actions.append(os.path.join(dirpath, name))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000223 actions.append(self.pkgname)
224 actions.sort()
225 actions.reverse()
226 for p in actions:
227 if os.path.isdir(p):
228 os.rmdir(p)
229 else:
230 os.remove(p)
231 del sys.path[0]
232
233 def test_module(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000234 eq = self.assertEqual
Victor Stinnerbf816222011-06-30 23:25:47 +0200235 create_empty_file(os.path.join(self.subpkgname, self.pkgname + '.py'))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000236 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation
237 eq(repr(areallylongpackageandmodulenametotestreprtruncation),
Victor Stinnere1ea8292011-02-23 14:14:48 +0000238 "<module %r from %r>" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__))
Neal Norwitz70769012001-12-29 00:25:42 +0000239 eq(repr(sys), "<module 'sys' (built-in)>")
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000240
241 def test_type(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000242 eq = self.assertEqual
Victor Stinnerbf816222011-06-30 23:25:47 +0200243 write_file(os.path.join(self.subpkgname, 'foo.py'), '''\
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000244class foo(object):
245 pass
246''')
247 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo
248 eq(repr(foo.foo),
Mark Hammondd800ae12003-01-16 04:56:52 +0000249 "<class '%s.foo'>" % foo.__name__)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000250
251 def test_object(self):
252 # XXX Test the repr of a type with a really long tp_name but with no
253 # tp_repr. WIBNI we had ::Inline? :)
254 pass
255
256 def test_class(self):
Victor Stinnerbf816222011-06-30 23:25:47 +0200257 write_file(os.path.join(self.subpkgname, 'bar.py'), '''\
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000258class bar:
259 pass
260''')
261 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar
Mark Hammondd800ae12003-01-16 04:56:52 +0000262 # Module name may be prefixed with "test.", depending on how run.
Ezio Melottib3aedd42010-11-20 19:04:17 +0000263 self.assertEqual(repr(bar.bar), "<class '%s.bar'>" % bar.__name__)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000264
265 def test_instance(self):
Victor Stinnerbf816222011-06-30 23:25:47 +0200266 write_file(os.path.join(self.subpkgname, 'baz.py'), '''\
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000267class baz:
268 pass
269''')
270 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz
271 ibaz = baz.baz()
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000272 self.assertTrue(repr(ibaz).startswith(
Guido van Rossuma48a3b42006-04-20 16:07:39 +0000273 "<%s.baz object at 0x" % baz.__name__))
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000274
275 def test_method(self):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000276 eq = self.assertEqual
Victor Stinnerbf816222011-06-30 23:25:47 +0200277 write_file(os.path.join(self.subpkgname, 'qux.py'), '''\
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000278class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
279 def amethod(self): pass
280''')
281 from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux
282 # Unbound methods first
Antoine Pitrou86a36b52011-11-25 18:56:07 +0100283 r = repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod)
284 self.assertTrue(r.startswith('<function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod'), r)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000285 # Bound method next
286 iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
Antoine Pitrou86a36b52011-11-25 18:56:07 +0100287 r = repr(iqux.amethod)
288 self.assertTrue(r.startswith(
Guido van Rossuma48a3b42006-04-20 16:07:39 +0000289 '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa object at 0x' \
Antoine Pitrou86a36b52011-11-25 18:56:07 +0100290 % (qux.__name__,) ), r)
Barry Warsaw0bcf6d82001-08-24 18:37:32 +0000291
292 def test_builtin_function(self):
293 # XXX test built-in functions and methods with really long names
294 pass
Fred Drake8e6669a2001-07-19 22:27:56 +0000295
296class ClassWithRepr:
297 def __init__(self, s):
298 self.s = s
299 def __repr__(self):
Guido van Rossuma48a3b42006-04-20 16:07:39 +0000300 return "ClassWithRepr(%r)" % self.s
Fred Drake8e6669a2001-07-19 22:27:56 +0000301
302
303class ClassWithFailingRepr:
304 def __repr__(self):
305 raise Exception("This should be caught by Repr.repr_instance")
306
Raymond Hettinger98a5f3f2010-09-13 21:36:00 +0000307class MyContainer:
308 'Helper class for TestRecursiveRepr'
309 def __init__(self, values):
310 self.values = list(values)
311 def append(self, value):
312 self.values.append(value)
313 @recursive_repr()
314 def __repr__(self):
315 return '<' + ', '.join(map(str, self.values)) + '>'
316
317class MyContainer2(MyContainer):
318 @recursive_repr('+++')
319 def __repr__(self):
320 return '<' + ', '.join(map(str, self.values)) + '>'
321
322class TestRecursiveRepr(unittest.TestCase):
323 def test_recursive_repr(self):
324 m = MyContainer(list('abcde'))
325 m.append(m)
326 m.append('x')
327 m.append(m)
328 self.assertEqual(repr(m), '<a, b, c, d, e, ..., x, ...>')
329 m = MyContainer2(list('abcde'))
330 m.append(m)
331 m.append('x')
332 m.append(m)
333 self.assertEqual(repr(m), '<a, b, c, d, e, +++, x, +++>')
Fred Drake8e6669a2001-07-19 22:27:56 +0000334
Fred Drake2e2be372001-09-20 21:33:42 +0000335def test_main():
336 run_unittest(ReprTests)
Ronald Oussoren94f25282010-05-05 19:11:21 +0000337 run_unittest(LongReprTest)
Raymond Hettinger98a5f3f2010-09-13 21:36:00 +0000338 run_unittest(TestRecursiveRepr)
Fred Drake2e2be372001-09-20 21:33:42 +0000339
340
341if __name__ == "__main__":
342 test_main()