Beispiel #1
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()),
          )),
     ])
Beispiel #2
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()),
          )),
     ])
Beispiel #3
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()),
         )),
     ])
Beispiel #4
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(),),
             )
         )
     ])
Beispiel #5
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(), )))])
Beispiel #6
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())
                            ),)
                        ),
                    )
                )
            ),

        ])
Beispiel #7
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(),),
                    ()
                )
            )

        ])
Beispiel #8
0
 def test_while(self):
     self.template([("while True: pass",
                     python.While(python.Name("True", python.Load()),
                                  (python.Pass(), ), ()))])