[Python-checkins] cpython: test AST base type garbage collection

benjamin.peterson python-checkins at python.org
Sun Jul 8 20:13:41 CEST 2012


http://hg.python.org/cpython/rev/5c2e30c484cf
changeset:   78008:5c2e30c484cf
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Jul 08 11:13:36 2012 -0700
summary:
  test AST base type garbage collection

files:
  Lib/test/test_ast.py |  15 ++++++++++++++-
  1 files changed, 14 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -1,8 +1,10 @@
 import os
 import sys
 import unittest
+import ast
+import weakref
+
 from test import support
-import ast
 
 def to_tuple(t):
     if t is None or isinstance(t, (str, int, complex)):
@@ -207,6 +209,17 @@
             # "_ast.AST constructor takes 0 positional arguments"
             ast.AST(2)
 
+    def test_AST_garbage_collection(self):
+        class X:
+            pass
+        a = ast.AST()
+        a.x = X()
+        a.x.a = a
+        ref = weakref.ref(a.x)
+        del a
+        support.gc_collect()
+        self.assertIsNone(ref())
+
     def test_snippets(self):
         for input, output, kind in ((exec_tests, exec_results, "exec"),
                                     (single_tests, single_results, "single"),

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list