summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_set.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_set.py')
-rw-r--r--Lib/test/test_set.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index a4830d4..6641ff8 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -21,6 +21,11 @@ class BadCmp:
def __eq__(self, other):
raise RuntimeError
+class ReprWrapper:
+ 'Used to test self-referential repr() calls'
+ def __repr__(self):
+ return repr(self.value)
+
class TestJointOps(unittest.TestCase):
# Tests common to both set and frozenset
@@ -244,6 +249,30 @@ class TestJointOps(unittest.TestCase):
self.assertRaises(RuntimeError, s.discard, BadCmp())
self.assertRaises(RuntimeError, s.remove, BadCmp())
+ def test_cyclical_repr(self):
+ w = ReprWrapper()
+ s = self.thetype([w])
+ w.value = s
+ if self.thetype == set:
+ self.assertEqual(repr(s), '{set(...)}')
+ else:
+ name = repr(s).partition('(')[0] # strip class name
+ self.assertEqual(repr(s), '%s([%s(...)])' % (name, name))
+
+ def test_cyclical_print(self):
+ w = ReprWrapper()
+ s = self.thetype([w])
+ w.value = s
+ try:
+ fo = open(test_support.TESTFN, "wb")
+ print >> fo, s,
+ fo.close()
+ fo = open(test_support.TESTFN, "rb")
+ self.assertEqual(fo.read(), repr(s))
+ finally:
+ fo.close()
+ os.remove(test_support.TESTFN)
+
class TestSet(TestJointOps):
thetype = set