Example #1
0
 def test_del(self):
     self.template([
         ("del a", python.Delete(targets=(
             python.Name("a", python.Del()),
         ))),
         ("del a, b", python.Delete(targets=(
             python.Name("a", python.Del()),
             python.Name("b", python.Del()),
         ))),
         ("del (a, b)", python.Delete(targets=(
             python.Tuple((
                 python.Name("a", python.Del()),
                 python.Name("b", python.Del()),
             ), python.Del()),
         ))),
         ("del (a\n, b)", python.Delete(targets=(
             python.Tuple((
                 python.Name("a", python.Del()),
                 python.Name("b", python.Del())
             ), python.Del()),
         ))),
         ("del (a\n, b), c", python.Delete(targets=(
             python.Tuple((
                 python.Name("a", python.Del()),
                 python.Name("b", python.Del())
             ), python.Del()),
             python.Name("c", python.Del()),
         ))),
     ])
Example #2
0
 def test_with(self):
     self.template([("""
             with some_context as some_name:
                 pass
             """,
                     python.With((python.withitem(
                         python.Name("some_context", python.Load()),
                         python.Name("some_name", python.Store()),
                     ), ), (python.Pass(), )))])
Example #3
0
 def test_assert(self):
     self.template([
         ("assert False",
          python.Assert(python.Name("False", python.Load()), None)),
         ("assert False, msg",
          python.Assert(
              python.Name("False", python.Load()),
              python.Name("msg", python.Load()),
          )),
     ])
Example #4
0
 def test_raise(self):
     self.template([
         ("raise", python.Raise(None, None)),
         ("raise err", python.Raise(python.Name("err", python.Load()),
                                    None)),
         ("raise err_1 from err_2",
          python.Raise(
              python.Name("err_1", python.Load()),
              python.Name("err_2", python.Load()),
          )),
     ])
Example #5
0
    def test_for(self):
        self.template([
            (
                "for x in li: pass",
                python.For(
                    python.Name("x", python.Store()),
                    python.Name("li", python.Load()),
                    (python.Pass(),),
                    ()
                )
            )

        ])
Example #6
0
 def test_assign(self):
     # Tests for type-info below..
     self.template([
         ("a = b", python.Assign(
             targets=(python.Name("a", python.Store()),),
             value=python.Name("b", python.Load()),
         )),
         ("a = b = c", python.Assign(
             targets=(
                 python.Name("a", python.Store()),
                 python.Name("b", python.Store()),
             ),
             value=python.Name("c", python.Load()),
         )),
     ])
Example #7
0
 def test_try(self):
     self.template([
         (
             """
             try:
                 pass
             except SomeException as error:
                 pass
             else:
                 pass
             finally:
                 pass
             """,
             python.Try(
                 (python.Pass(),),
                 (python.ExceptHandler(
                     python.Name("SomeException", python.Load()),
                     "error",
                     (python.Pass(),)
                 ),),
                 (python.Pass(),),
                 (python.Pass(),),
             )
         )
     ])
Example #8
0
    def test_if(self):
        self.template([
            (
                """
                if True:
                    pass
                """,
                python.If(
                    python.NameConstant(True),
                    (python.Pass(),),
                    ()
                )
            ),
            (
                """
                if first_cond:
                    first
                elif second_cond:
                    second
                else:
                    third
                """,
                python.If(
                    python.Name(
                        "first_cond", python.Load()
                    ),
                    (python.Expr(
                        python.Name("first", python.Load())
                    ),),
                    (
                        python.If(
                            python.Name("second_cond", python.Load()),
                            (python.Expr(
                                python.Name("second", python.Load())
                            ),),
                            (python.Expr(
                                python.Name("third", python.Load())
                            ),)
                        ),
                    )
                )
            ),

        ])
Example #9
0
 def visit_Name(self, node):
     if node.id in ["True", "False", "None"]:
         return python.NameConstant(eval(node.id))
     else:
         self.generic_visit(node)
         return python.Name(node.id, node.ctx)
Example #10
0
 def test_while(self):
     self.template([("while True: pass",
                     python.While(python.Name("True", python.Load()),
                                  (python.Pass(), ), ()))])