(self)
| 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. |
nothing calls this directly
no test coverage detected