예제 #1
0
 def test_if(self):
     self.stmt(ast.If(ast.Num(self.space.wrap(3), 0, 0), [], [], 0, 0),
               "empty body on If")
     i = ast.If(ast.Name("x", ast.Store, 0, 0), [ast.Pass(0, 0)], [], 0, 0)
     self.stmt(i, "must have Load context")
     i = ast.If(ast.Num(self.space.wrap(3), 0, 0),
                [ast.Expr(ast.Name("x", ast.Store, 0, 0), 0, 0)], [], 0, 0)
     self.stmt(i, "must have Load context")
     i = ast.If(ast.Num(self.space.wrap(3), 0, 0), [ast.Pass(0, 0)],
                [ast.Expr(ast.Name("x", ast.Store, 0, 0), 0, 0)], 0, 0)
     self.stmt(i, "must have Load context")
예제 #2
0
 def test_expr(self, space):
     value = space.wrap(42)
     node = ast.Num(value, lineno=1, col_offset=1)
     expr = ast.Expr(node, lineno=1, col_offset=1)
     w_node = expr.to_object(space)
     # node.value.n
     assert space.getattr(space.getattr(w_node, space.wrap("value")),
                          space.wrap("n")) is value
예제 #3
0
 def test_while(self):
     self.stmt(ast.While(ast.Num(self.space.wrap(3), 0, 0), [], [], 0, 0),
               "empty body on While")
     self.stmt(
         ast.While(ast.Name("x", ast.Store, 0, 0), [ast.Pass(0, 0)], [], 0,
                   0), "must have Load context")
     self.stmt(
         ast.While(ast.Num(self.space.wrap(3), 0, 0), [ast.Pass(0, 0)],
                   [ast.Expr(ast.Name("x", ast.Store, 0, 0), 0, 0)], 0, 0),
         "must have Load context")
예제 #4
0
 def test_for(self):
     x = ast.Name("x", ast.Store, 0, 0)
     y = ast.Name("y", ast.Load, 0, 0)
     p = ast.Pass(0, 0)
     self.stmt(ast.For(x, y, [], [], 0, 0), "empty body on For")
     self.stmt(ast.For(ast.Name("x", ast.Load, 0, 0), y, [p], [], 0, 0),
               "must have Store context")
     self.stmt(ast.For(x, ast.Name("y", ast.Store, 0, 0), [p], [], 0, 0),
               "must have Load context")
     e = ast.Expr(ast.Name("x", ast.Store, 0, 0), 0, 0)
     self.stmt(ast.For(x, y, [e], [], 0, 0), "must have Load context")
     self.stmt(ast.For(x, y, [p], [e], 0, 0), "must have Load context")
예제 #5
0
 def test_try(self):
     p = ast.Pass(0, 0)
     t = ast.Try([], [], [], [p], 0, 0)
     self.stmt(t, "empty body on Try")
     t = ast.Try([ast.Expr(ast.Name("x", ast.Store, 0, 0), 0, 0)], [], [],
                 [p], 0, 0)
     self.stmt(t, "must have Load context")
     t = ast.Try([p], [], [], [], 0, 0)
     self.stmt(t, "Try has neither except handlers nor finalbody")
     t = ast.Try([p], [], [p], [p], 0, 0)
     self.stmt(t, "Try has orelse but no except handlers")
     t = ast.Try([p], [ast.ExceptHandler(None, "x", [], 0, 0)], [], [], 0,
                 0)
     self.stmt(t, "empty body on ExceptHandler")
     e = [ast.ExceptHandler(ast.Name("x", ast.Store, 0, 0), "y", [p], 0, 0)]
     self.stmt(ast.Try([p], e, [], [], 0, 0), "must have Load context")
     e = [ast.ExceptHandler(None, "x", [p], 0, 0)]
     t = ast.Try([p], e, [ast.Expr(ast.Name("x", ast.Store, 0, 0), 0, 0)],
                 [p], 0, 0)
     self.stmt(t, "must have Load context")
     t = ast.Try([p], e, [p],
                 [ast.Expr(ast.Name("x", ast.Store, 0, 0), 0, 0)], 0, 0)
     self.stmt(t, "must have Load context")
예제 #6
0
 def test_module(self):
     m = ast.Interactive([ast.Expr(ast.Name("x", ast.Store, 0, 0), 0, 0)])
     self.mod(m, "must have Load context", "single")
     m = ast.Expression(ast.Name("x", ast.Store, 0, 0))
     self.mod(m, "must have Load context", "eval")
예제 #7
0
 def expr(self, node, msg=None, exc=validate.ValidationError):
     mod = ast.Module([ast.Expr(node, 0, 0)])
     self.mod(mod, msg, exc=exc)
예제 #8
0
 def test_expr(self):
     e = ast.Expr(ast.Name("x", ast.Store, 0, 0), 0, 0)
     self.stmt(e, "must have Load context")