MCPcopy Index your code
hub / github.com/python/cpython / test_cyclic_gc

Method test_cyclic_gc

Lib/test/test_xml_etree.py:2710–2743  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2708 self.assertRaises(TypeError, copy.deepcopy, e)
2709
2710 def test_cyclic_gc(self):
2711 class Dummy:
2712 pass
2713
2714 # Test the shortest cycle: d->element->d
2715 d = Dummy()
2716 d.dummyref = ET.Element('joe', attr=d)
2717 wref = weakref.ref(d)
2718 del d
2719 gc_collect()
2720 self.assertIsNone(wref())
2721
2722 # A longer cycle: d->e->e2->d
2723 e = ET.Element('joe')
2724 d = Dummy()
2725 d.dummyref = e
2726 wref = weakref.ref(d)
2727 e2 = ET.SubElement(e, 'foo', attr=d)
2728 del d, e, e2
2729 gc_collect()
2730 self.assertIsNone(wref())
2731
2732 # A cycle between Element objects as children of one another
2733 # e1->e2->e3->e1
2734 e1 = ET.Element('e1')
2735 e2 = ET.Element('e2')
2736 e3 = ET.Element('e3')
2737 e3.append(e1)
2738 e2.append(e3)
2739 e1.append(e2)
2740 wref = weakref.ref(e1)
2741 del e1, e2, e3
2742 gc_collect()
2743 self.assertIsNone(wref())
2744
2745 def test_weakref(self):
2746 flag = False

Callers

nothing calls this directly

Calls 4

appendMethod · 0.95
gc_collectFunction · 0.90
assertIsNoneMethod · 0.80
DummyClass · 0.70

Tested by

no test coverage detected