MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_deepcopy_clear

Method test_deepcopy_clear

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

Source from the content-addressed store, hash-verified

3102 gc_collect()
3103
3104 def test_deepcopy_clear(self):
3105 # Prevent crashes when __deepcopy__() clears the children list.
3106 # See https://github.com/python/cpython/issues/133009.
3107 class X(ET.Element):
3108 def __deepcopy__(self, memo):
3109 root.clear()
3110 return self
3111
3112 root = ET.Element('a')
3113 evil = X('x')
3114 root.extend([evil, ET.Element('y')])
3115 if is_python_implementation():
3116 # Mutating a list over which we iterate raises an error.
3117 self.assertRaises(RuntimeError, copy.deepcopy, root)
3118 else:
3119 c = copy.deepcopy(root)
3120 # In the C implementation, we can still copy the evil element.
3121 self.assertListEqual(list(c), [evil])
3122
3123 def test_deepcopy_grow(self):
3124 # 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