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

Method test_deepcopy_grow

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

Source from the content-addressed store, hash-verified

3166 self.assertListEqual(list(c), [evil])
3167
3168 def test_deepcopy_grow(self):
3169 # Prevent crashes when __deepcopy__() mutates the children list.
3170 # See https://github.com/python/cpython/issues/133009.
3171 a = ET.Element('a')
3172 b = ET.Element('b')
3173 c = ET.Element('c')
3174
3175 class X(ET.Element):
3176 def __deepcopy__(self, memo):
3177 root.append(a)
3178 root.append(b)
3179 return self
3180
3181 root = ET.Element('top')
3182 evil1, evil2 = X('1'), X('2')
3183 root.extend([evil1, c, evil2])
3184 children = list(copy.deepcopy(root))
3185 # mock deep copies
3186 self.assertIs(children[0], evil1)
3187 self.assertIs(children[2], evil2)
3188 # true deep copies
3189 self.assertEqual(children[1].tag, c.tag)
3190 self.assertEqual([c.tag for c in children[3:]],
3191 [a.tag, b.tag, a.tag, b.tag])
3192
3193
3194class MutationDeleteElementPath(str):

Callers

nothing calls this directly

Calls 5

extendMethod · 0.95
listClass · 0.85
XClass · 0.70
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected