def test_walk_astroid(self):
atok = asttokens.ASTTokens(self.source, tree=astroid.builder.parse(self.source))
def view(node):
return "%s:%s" % (node.__class__.__name__, atok.get_text(node))
scan = [view(n) for n in asttokens.util.walk(atok.tree)]
self.assertEqual(scan, [
"Module:foo(bar(1 + 2), 'hello' + ', ' + 'world')",
"Expr:foo(bar(1 + 2), 'hello' + ', ' + 'world')",
"Call:foo(bar(1 + 2), 'hello' + ', ' + 'world')",
'Name:foo',
'Call:bar(1 + 2)',
'Name:bar',
'BinOp:1 + 2',
'Const:1',
'Const:2',
"BinOp:'hello' + ', ' + 'world'",
"BinOp:'hello' + ', '",
"Const:'hello'",
"Const:', '",
"Const:'world'"
])
评论列表
文章目录