summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_iter.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py
index 5bd7ba4..13ed5bd 100644
--- a/Lib/test/test_iter.py
+++ b/Lib/test/test_iter.py
@@ -747,6 +747,29 @@ class TestCase(unittest.TestCase):
(a, b), (c,) = IteratingSequenceClass(2), {42: 24}
self.assertEqual((a, b, c), (0, 1, 42))
+ # Test reference count behavior
+
+ class C(object):
+ count = 0
+ def __new__(cls):
+ cls.count += 1
+ return object.__new__(cls)
+ def __del__(self):
+ cls = self.__class__
+ assert cls.count > 0
+ cls.count -= 1
+ x = C()
+ self.assertEqual(C.count, 1)
+ del x
+ self.assertEqual(C.count, 0)
+ l = [C(), C(), C()]
+ self.assertEqual(C.count, 3)
+ try:
+ a, b = iter(l)
+ except ValueError:
+ pass
+ del l
+ self.assertEqual(C.count, 0)
def test_main():
run_unittest(TestCase)