(self)
| 1130 | |
| 1131 | @skip_if_unlimited_stack_size |
| 1132 | def test_copy_with_parents(self): |
| 1133 | # gh-120108 |
| 1134 | code = """ |
| 1135 | ('',) |
| 1136 | while i < n: |
| 1137 | if ch == '': |
| 1138 | ch = format[i] |
| 1139 | if ch == '': |
| 1140 | if freplace is None: |
| 1141 | '' % getattr(object) |
| 1142 | elif ch == '': |
| 1143 | if zreplace is None: |
| 1144 | if hasattr: |
| 1145 | offset = object.utcoffset() |
| 1146 | if offset is not None: |
| 1147 | if offset.days < 0: |
| 1148 | offset = -offset |
| 1149 | h = divmod(timedelta(hours=0)) |
| 1150 | if u: |
| 1151 | zreplace = '' % (sign,) |
| 1152 | elif s: |
| 1153 | zreplace = '' % (sign,) |
| 1154 | else: |
| 1155 | zreplace = '' % (sign,) |
| 1156 | elif ch == '': |
| 1157 | if Zreplace is None: |
| 1158 | Zreplace = '' |
| 1159 | if hasattr(object): |
| 1160 | s = object.tzname() |
| 1161 | if s is not None: |
| 1162 | Zreplace = s.replace('') |
| 1163 | newformat.append(Zreplace) |
| 1164 | else: |
| 1165 | push('') |
| 1166 | else: |
| 1167 | push(ch) |
| 1168 | |
| 1169 | """ |
| 1170 | tree = ast.parse(textwrap.dedent(code)) |
| 1171 | for node in ast.walk(tree): |
| 1172 | for child in ast.iter_child_nodes(node): |
| 1173 | child.parent = node |
| 1174 | try: |
| 1175 | with support.infinite_recursion(200): |
| 1176 | tree2 = copy.deepcopy(tree) |
| 1177 | finally: |
| 1178 | # Singletons like ast.Load() are shared; make sure we don't |
| 1179 | # leave them mutated after this test. |
| 1180 | for node in ast.walk(tree): |
| 1181 | if hasattr(node, "parent"): |
| 1182 | del node.parent |
| 1183 | |
| 1184 | for node in ast.walk(tree2): |
| 1185 | for child in ast.iter_child_nodes(node): |
| 1186 | if hasattr(child, "parent") and not isinstance(child, ( |
| 1187 | ast.expr_context, ast.boolop, ast.unaryop, ast.cmpop, ast.operator, |
| 1188 | )): |
| 1189 | self.assertEqual(to_tuple(child.parent), to_tuple(node)) |
nothing calls this directly
no test coverage detected