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

Method test_node_mutate

Lib/test/test_ast/test_ast.py:3139–3156  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3137 self.assertASTTransformation(ExtendKeywords, code, expected)
3138
3139 def test_node_mutate(self):
3140 code = """
3141 def func(arg):
3142 print(arg)
3143 """
3144 expected = """
3145 def func(arg):
3146 log(arg)
3147 """
3148
3149 class PrintToLog(ast.NodeTransformer):
3150 def visit_Call(self, node: ast.Call):
3151 self.generic_visit(node)
3152 if isinstance(node.func, ast.Name) and node.func.id == 'print':
3153 node.func.id = 'log'
3154 return node
3155
3156 self.assertASTTransformation(PrintToLog, code, expected)
3157
3158 def test_node_replace(self):
3159 code = """

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected