def test_call(self): root = ast.parse('a(1, x=2, *y, **z)') p = NodePath.from_string(root, '/0//func') self.assertIs(p(), root.body[0].value.func) self.assertEqual(p().id, 'a') p = NodePath.from_string(root, '/0//args:0') self.assertIs(p(), root.body[0].value.args[0]) self.assertEqual(p().n, 1) p = NodePath.from_string(root, '/0//keywords:0') self.assertIs(p(), root.body[0].value.keywords[0]) self.assertEqual(p().arg, 'x') self.assertEqual(p().value.n, 2) p = NodePath.from_string(root, '/0//starargs') self.assertIs(p(), root.body[0].value.starargs) self.assertEqual(p().id, 'y') p = NodePath.from_string(root, '/0//kwargs') self.assertIs(p(), root.body[0].value.kwargs) self.assertEqual(p().id, 'z')
def test_binop(self): root = ast.parse('1 + 2') p = NodePath.from_string(root, '/0//left') self.assertIs(p(), root.body[0].value.left) self.assertEqual(p().n, 1)
def test_expr0value(self): root = ast.parse('1') p = NodePath.from_string(root, '/0/') self.assertIs(p(), root.body[0].value)
def test_expr1(self): root = ast.parse('1\n2\n3') p = NodePath.from_string(root, '/1') self.assertIs(p(), root.body[1])
def test_root(self): root = ast.parse('1') p = NodePath.from_string(root, '/') self.assertIs(p(), root)