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

Method test_deepcopy_clear

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

Source from the content-addressed store, hash-verified

3147 gc_collect()
3148
3149 def test_deepcopy_clear(self):
3150 # Prevent crashes when __deepcopy__() clears the children list.
3151 # See https://github.com/python/cpython/issues/133009.
3152 class X(ET.Element):
3153 def __deepcopy__(self, memo):
3154 root.clear()
3155 return self
3156
3157 root = ET.Element('a')
3158 evil = X('x')
3159 root.extend([evil, ET.Element('y')])
3160 if is_python_implementation():
3161 # Mutating a list over which we iterate raises an error.
3162 self.assertRaises(RuntimeError, copy.deepcopy, root)
3163 else:
3164 c = copy.deepcopy(root)
3165 # In the C implementation, we can still copy the evil element.
3166 self.assertListEqual(list(c), [evil])
3167
3168 def test_deepcopy_grow(self):
3169 # Prevent crashes when __deepcopy__() mutates the children list.

Callers

nothing calls this directly

Calls 6

extendMethod · 0.95
is_python_implementationFunction · 0.85
listClass · 0.85
assertListEqualMethod · 0.80
XClass · 0.70
assertRaisesMethod · 0.45

Tested by

no test coverage detected