diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-01 15:35:33 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-01 15:35:33 (GMT) |
commit | 7ddda7830c362f59f154681fe9b2aa0c161309b1 (patch) | |
tree | 6ed81212c2f0a90fabc058a04c516d9139477fa8 /Lib | |
parent | 75edad0502c648148c6139b2d81a128559573c0d (diff) | |
download | cpython-7ddda7830c362f59f154681fe9b2aa0c161309b1.zip cpython-7ddda7830c362f59f154681fe9b2aa0c161309b1.tar.gz cpython-7ddda7830c362f59f154681fe9b2aa0c161309b1.tar.bz2 |
Merged revisions 68128 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68128 | antoine.pitrou | 2009-01-01 15:11:22 +0100 (jeu., 01 janv. 2009) | 3 lines
Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_deque.py | 21 | ||||
-rw-r--r-- | Lib/test/test_dict.py | 16 | ||||
-rw-r--r-- | Lib/test/test_set.py | 17 |
3 files changed, 50 insertions, 4 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index 7af0803..27c89c4 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -1,7 +1,8 @@ from collections import deque import unittest from test import support, seq_tests -from weakref import proxy +import gc +import weakref import copy import pickle from io import StringIO @@ -420,6 +421,22 @@ class TestBasic(unittest.TestCase): d.append(1) gc.collect() + def test_container_iterator(self): + # Bug #3680: tp_traverse was not implemented for deque iterator objects + class C(object): + pass + for i in range(2): + obj = C() + ref = weakref.ref(obj) + if i == 0: + container = deque([obj, 1]) + else: + container = reversed(deque([obj, 1])) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestVariousIteratorArgs(unittest.TestCase): def test_constructor(self): @@ -530,7 +547,7 @@ class TestSubclass(unittest.TestCase): def test_weakref(self): d = deque('gallahad') - p = proxy(d) + p = weakref.proxy(d) self.assertEqual(str(p), str(d)) d = None self.assertRaises(ReferenceError, str, p) diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index 403d5eb..2e74b68 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -2,6 +2,7 @@ import unittest from test import support import sys, collections, random, string +import gc, weakref class DictTest(unittest.TestCase): @@ -648,6 +649,21 @@ class DictTest(unittest.TestCase): pass d = {} + def test_container_iterator(self): + # Bug #3680: tp_traverse was not implemented for dictiter and + # dictview objects. + class C(object): + pass + views = (dict.items, dict.values, dict.keys) + for v in views: + obj = C() + ref = weakref.ref(obj) + container = {obj: 1} + obj.v = v(container) + obj.x = iter(obj.v) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") from test import mapping_tests diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index da3ed0f..5a8819f 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -1,6 +1,7 @@ import unittest from test import support -from weakref import proxy +import gc +import weakref import operator import copy import pickle @@ -323,6 +324,18 @@ class TestJointOps(unittest.TestCase): self.assertEqual(sum(elem.hash_count for elem in d), n) self.assertEqual(d3, dict.fromkeys(d, 123)) + def test_container_iterator(self): + # Bug #3680: tp_traverse was not implemented for set iterator object + class C(object): + pass + obj = C() + ref = weakref.ref(obj) + container = set([obj, 1]) + obj.x = iter(container) + del obj, container + gc.collect() + self.assert_(ref() is None, "Cycle was not collected") + class TestSet(TestJointOps): thetype = set basetype = set @@ -546,7 +559,7 @@ class TestSet(TestJointOps): def test_weakref(self): s = self.thetype('gallahad') - p = proxy(s) + p = weakref.proxy(s) self.assertEqual(str(p), str(s)) s = None self.assertRaises(ReferenceError, str, p) |