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