Exemple #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(),),
             )
         )
     ])
Exemple #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"))),
     ])
Exemple #3
0
    def test_statements(self):
        self.prefix = "for x in li:"

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

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

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

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

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