Beispiel #1
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 #2
0
 def test_statements(self):
     self.template([
         ("pass", python.Pass()),
         ("global a", python.Global(('a',))),
         ("global a, b", python.Global(('a', "b"))),
         ("nonlocal a", python.Nonlocal(('a',))),
         ("nonlocal a, b", python.Nonlocal(('a', "b"))),
     ])
Beispiel #3
0
    def test_statements(self):
        self.prefix = "for x in li:"

        self.template([
            ("pass", python.Pass()),
            ("break", python.Break()),
            ("continue", python.Continue()),
        ])
Beispiel #4
0
    def test_while(self):
        self.prefix = "while True:"

        self.template([
            ("pass", python.Pass()),
            ("break", python.Break()),
            ("continue", python.Continue()),
        ])
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_while(self):
        self.template([
            (
                "while True: pass",
                python.While(
                    python.NameConstant(True),
                    (python.Pass(),),
                    ()
                )
            )

        ])
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_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 #9
0
 def test_while(self):
     self.template([("while True: pass",
                     python.While(python.Name("True", python.Load()),
                                  (python.Pass(), ), ()))])