summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xml_etree.py
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2012-03-30 13:38:33 (GMT)
committerEli Bendersky <eliben@gmail.com>2012-03-30 13:38:33 (GMT)
commit0192ba33b4ff53aa747077b995b6f7fa612e788e (patch)
treecbfc77633620633d93d492ac831a11928d081008 /Lib/test/test_xml_etree.py
parent1e257550063a99bc54fea1696ed8fdd8542eb52a (diff)
downloadcpython-0192ba33b4ff53aa747077b995b6f7fa612e788e.zip
cpython-0192ba33b4ff53aa747077b995b6f7fa612e788e.tar.gz
cpython-0192ba33b4ff53aa747077b995b6f7fa612e788e.tar.bz2
Issue #14065: Added cyclic GC support to ET.Element
Diffstat (limited to 'Lib/test/test_xml_etree.py')
-rw-r--r--Lib/test/test_xml_etree.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 8a1ea0f..00eafe1 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -14,9 +14,10 @@
# Don't re-import "xml.etree.ElementTree" module in the docstring,
# except if the test is specific to the Python implementation.
-import sys
+import gc
import html
import io
+import sys
import unittest
from test import support
@@ -1846,6 +1847,30 @@ class BasicElementTest(unittest.TestCase):
self.assertRaises(TypeError, e.extend, [ET.Element('bar'), 'foo'])
self.assertRaises(TypeError, e.insert, 0, 'foo')
+ def test_cyclic_gc(self):
+ class ShowGC:
+ def __init__(self, flaglist):
+ self.flaglist = flaglist
+ def __del__(self):
+ self.flaglist.append(1)
+
+ # Test the shortest cycle: lst->element->lst
+ fl = []
+ lst = [ShowGC(fl)]
+ lst.append(ET.Element('joe', attr=lst))
+ del lst
+ gc.collect()
+ self.assertEqual(fl, [1])
+
+ # A longer cycle: lst->e->e2->lst
+ fl = []
+ e = ET.Element('joe')
+ lst = [ShowGC(fl), e]
+ e2 = ET.SubElement(e, 'foo', attr=lst)
+ del lst, e, e2
+ gc.collect()
+ self.assertEqual(fl, [1])
+
class ElementTreeTest(unittest.TestCase):
def test_istype(self):