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