Ejemplo n.º 1
0
    def test_if_inputs(self):
        
        def f():
            t = True
            c = 42
            if t:
                x = c
            else:
                x = c
            return x

        expected = G(
            T(1, tasks.ConstTask(True), {'quick':True}),
            T(2, tasks.ConstTask(42), {'quick':True}),
            C(1, "value", 3, "$test"),
            C(2, "value", 3, "c"),
            T(3, tasks.IfTask(G(
                C(START_TICK, "c", FINAL_TICK, "x")
            ), G(
                C(START_TICK, "c", FINAL_TICK, "x")
            ))),
            C(3, "x", FINAL_TICK, "retval")
        )
   
        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 2
0
    def test_for_break(self):
        def f(lst, x):
            for x in lst:
                if True:
                    break
            return x

        with graph_factory():
            expected = G(
                C(START_TICK, "lst", 1, "iterable"),
                T(1, tasks.IterTask(), {'quick': True}),
                C(1, "value", 2, "$iterator"), C(START_TICK, "x", 2, "x"),
                T(
                    2,
                    tasks.ForTask(
                        False, False,
                        G(
                            "body", T(1, tasks.ConstTask(True),
                                      {'quick': True}),
                            C(1, "value", 2, "$breaked"),
                            C(START_TICK, "$target", 2, "x"),
                            C(START_TICK, "$iterator", 2, "$iterator"),
                            T(2, tasks.ForTask(True, True, G("body"),
                                               G("else"))),
                            C(2, "x", FINAL_TICK, "x")), G("else"))),
                C(2, "x", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 3
0
    def test_while(self):
        def f(x):
            while x:
                pass
            return x

        with graph_factory():
            expected = G(
                C(START_TICK, "x", 1, "$test"), C(START_TICK, "x", 1, "x"),
                T(
                    1,
                    tasks.WhileTask(
                        False, False,
                        G(
                            "body",
                            C(START_TICK, "x", 1, "$test"),
                            C(START_TICK, "x", 1, "x"),
                            T(
                                1,
                                tasks.WhileTask(True, False, G("body"),
                                                G("else"))),
                        ), G("else"))), C(START_TICK, "x", FINAL_TICK,
                                          "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 4
0
    def test_if_half_assigned(self):
        
        def f():
            t = True
            x = 1
            if t:
                pass
            else:
                x = 2
            return x

        expected = G(
            T(1, tasks.ConstTask(True), {'quick':True}),
            T(2, tasks.ConstTask(1), {'quick':True}),
            C(1, "value", 3, "$test"),
            C(2, "value", 3, "x"),
            T(3, tasks.IfTask(G(
            ), G(
                T(1, tasks.ConstTask(2), {'quick':True}),
                C(1, "value", FINAL_TICK, "x")
            ))),
            C(3, "x", FINAL_TICK, "retval")
        )
   
        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 5
0
    def test_while_break(self):
        def f(x):
            while x:
                if True:
                    break
            return x

        with graph_factory():
            expected = G(
                C(START_TICK, "x", 1, "$test"), C(START_TICK, "x", 1, "x"),
                T(
                    1,
                    tasks.WhileTask(
                        False, False,
                        G(
                            "body",
                            C(START_TICK, "x", 2, "$test"),
                            C(START_TICK, "x", 2, "x"),
                            T(1, tasks.ConstTask(True), {'quick': True}),
                            C(1, "value", 2, "$breaked"),
                            T(
                                2,
                                tasks.WhileTask(True, True, G("body"),
                                                G("else"))),
                        ), G("else"))), C(START_TICK, "x", FINAL_TICK,
                                          "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 6
0
    def test_for_break(self):
        
        def f(lst, x):
            for x in lst:
                if True:
                    break
            return x
            
        with graph_factory():
            expected = G(
              C(START_TICK, "lst", 1, "iterable"),
              T(1, tasks.IterTask(), {'quick':True}),
              C(1, "value", 2, "$iterator"),
              C(START_TICK, "x", 2, "x"),
              T(2, tasks.ForTask(False, False, G("body",
                  T(1, tasks.ConstTask(True), {'quick':True}),
                  C(1, "value", 2, "$breaked"),
                  C(START_TICK, "$target",2 , "x"),
                  C(START_TICK, "$iterator", 2, "$iterator"),
                  T(2, tasks.ForTask(True, True, G("body"), G("else"))),
                  C(2, "x", FINAL_TICK, "x")
              ), G("else"))),
              C(2, "x", FINAL_TICK, "retval")
            )

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 7
0
    def test_str(self):
        def f():
            return "Hello World!"

        expected = G(T(1, tasks.ConstTask("Hello World!"), {'quick': True}),
                     C(1, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 8
0
    def test_unaryop(self):
        def f(a):
            return ~a

        expected = G(C(START_TICK, "a", 1, "value"),
                     T(1, tasks.UnaryOpTask(ast.Invert()), {'quick': True}),
                     C(1, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 9
0
    def test_attribute(self):
        def f(a):
            return a.myattr

        expected = G(C(START_TICK, "a", 1, "object"),
                     T(1, tasks.AttributeTask("myattr"), {'quick': True}),
                     C(1, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 10
0
    def test_tuple_assign(self):
        def f(x):
            a, b, c = x
            return c

        expected = G(C(START_TICK, "x", 1, "value"),
                     T(1, tasks.UnpackTask(3), {'quick': True}),
                     C(1, "2", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 11
0
    def test_compare(self):
        def f(a, b):
            return a == b

        expected = G(C(START_TICK, "a", 1, "left"),
                     C(START_TICK, "b", 1, "right"),
                     T(1, tasks.BinOpTask(ast.Eq()), {'quick': True}),
                     C(1, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 12
0
    def test_call_kwargs(self):
        def f(a, b):
            return a(**b)

        expected = G(
            C(START_TICK, "a", 1, "func"), C(START_TICK, "b", 1, "kwargs"),
            T(1, tasks.CallTask(0, [], False, True), {'syncpoint': True}),
            C(1, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 13
0
    def test_slice(self):
        def f(a, b):
            return a[b]

        expected = G(C(START_TICK, "a", 1, "object"),
                     C(START_TICK, "b", 1, "slice"),
                     T(1, tasks.SubscriptTask(), {'quick': True}),
                     C(1, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 14
0
    def test_tuple(self):
        def f(v1, v2):
            return (v1, v2)

        expected = G(C(START_TICK, "v1", 1, "value_0"),
                     C(START_TICK, "v2", 1, "value_1"),
                     T(1, tasks.TupleTask(2), {'quick': True}),
                     C(1, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 15
0
    def test_readglobal(self):
        def f():
            return __pydron_read_global__(
                "TestTranslator")  #@UndefinedVariable

        expected = G(T(1, tasks.ConstTask("TestTranslator"), {'quick': True}),
                     C(1, "value", 2, "var"),
                     T(2, tasks.ReadGlobal(__name__), {'quick': True}),
                     C(2, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 16
0
    def test_call_karg(self):
        def f(a, b, c):
            return a(foo=b, bar=c)

        expected = G(
            C(START_TICK, "a", 1, "func"), C(START_TICK, "b", 1, "karg_0"),
            C(START_TICK, "c", 1, "karg_1"),
            T(1, tasks.CallTask(0, ['foo', 'bar'], False, False),
              {'syncpoint': True}), C(1, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 17
0
 def test_str(self):
     
     def f():
         return "Hello World!"
     
     expected = G(
         T(1, tasks.ConstTask("Hello World!"), {'quick':True}),
         C(1, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 18
0
    def test_call_builtin(self):
        def f():
            return __pydron_new_cell__("x")  #@UndefinedVariable

        expected = G(
            T(1, tasks.ConstTask("x"), {'quick': True}),
            C(1, "value", 2, "arg0"),
            T(2, tasks.BuiltinCallTask(builtins.__pydron_new_cell__, 1),
              {'quick': True}), C(2, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 19
0
 def test_attribute(self):
     
     def f(a):
         return a.myattr
     
     expected = G(
         C(START_TICK, "a", 1, "object"),
         T(1, tasks.AttributeTask("myattr"), {'quick':True}),
         C(1, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 20
0
 def test_unaryop(self):
     
     def f(a):
         return ~a
     
     expected = G(
         C(START_TICK, "a", 1, "value"),
         T(1, tasks.UnaryOpTask(ast.Invert()), {'quick':True}),
         C(1, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 21
0
    def test_dict(self):
        def f(k1, v1, k2, v2):
            return {k1: v1, k2: v2}

        expected = G(C(START_TICK, "k1", 1, "key_0"),
                     C(START_TICK, "v1", 1, "value_0"),
                     C(START_TICK, "k2", 1, "key_1"),
                     C(START_TICK, "v2", 1, "value_1"),
                     T(1, tasks.DictTask(2), {'quick': True}),
                     C(1, "value", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 22
0
 def test_call_builtin(self):
     def f():
         return __pydron_new_cell__("x") #@UndefinedVariable
     
     expected = G(
         T(1, tasks.ConstTask("x"), {'quick': True}),
         C(1, "value", 2, "arg0"),
         T(2, tasks.BuiltinCallTask(builtins.__pydron_new_cell__, 1), {'quick': True}),
         C(2, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 23
0
    def test_raise(self):
        def f(x):
            raise x
            return x

        expected = G(T(1, tasks.ConstTask(None), {'quick': True}),
                     C(1, "value", 2, "inst"), C(START_TICK, "x", 2, "type"),
                     C(1, "value", 2, "tback"),
                     T(2, tasks.RaiseTask(), {'quick': True}),
                     C(START_TICK, "x", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 24
0
 def test_call(self):
     
     def f(a):
         return a()
     
     expected = G(
         C(START_TICK, "a", 1, "func"),
         T(1, tasks.CallTask(0, [], False, False), {'syncpoint':True}),
         C(1, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 25
0
    def test_augassign_attr(self):
        def f(a, b):
            a.myattr += b
            return a

        expected = G(
            C(START_TICK, "a", 1, "target"), C(START_TICK, "b", 1, "value"),
            T(1, tasks.AugAttrAssignTask(ast.Add(), "myattr"), {
                'quick': True,
                'syncpoint': True
            }), C(START_TICK, "a", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 26
0
    def test_attribute_assign(self):
        def f(x, y):
            x.myattribute = y
            return x

        expected = G(
            C(START_TICK, "x", 1, "object"), C(START_TICK, "y", 1, "value"),
            T(1, tasks.AttrAssign("myattribute"), {
                'quick': True,
                'syncpoint': True
            }), C(START_TICK, "x", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 27
0
 def test_slice(self):
     
     def f(a,b):
         return a[b]
     
     expected = G(
         C(START_TICK, "a", 1, "object"),
         C(START_TICK, "b", 1, "slice"),
         T(1, tasks.SubscriptTask(), {'quick':True}),
         C(1, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 28
0
 def test_compare(self):
     
     def f(a, b):
         return a == b
     
     expected = G(
         C(START_TICK, "a", 1, "left"),
         C(START_TICK, "b", 1, "right"),
         T(1, tasks.BinOpTask(ast.Eq()), {'quick':True}),
         C(1, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 29
0
 def test_tuple_assign(self):
     
     def f(x):
         a, b, c = x
         return c
         
     expected = G(
         C(START_TICK, "x", 1, "value"),
         T(1, tasks.UnpackTask(3), {'quick':True}),
         C(1, "2", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 30
0
 def test_tuple(self):
     
     def f(v1, v2):
         return (v1, v2)
     
     expected = G(
         C(START_TICK, "v1", 1, "value_0"),
         C(START_TICK, "v2", 1, "value_1"),
         T(1, tasks.TupleTask(2), {'quick':True}),
         C(1, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 31
0
    def test_augassign_subscript(self):
        def f(a, b, i):
            a[i] += b
            return a

        expected = G(
            C(START_TICK, "a", 1, "target"), C(START_TICK, "b", 1, "value"),
            C(START_TICK, "i", 1, "slice"),
            T(1, tasks.AugSubscriptAssignTask(ast.Add()), {
                'quick': True,
                'syncpoint': True
            }), C(START_TICK, "a", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 32
0
    def test_subscript_assign(self):
        def f(x, y, z):
            x[y] = z
            return x

        expected = G(
            C(START_TICK, "x", 1, "object"), C(START_TICK, "y", 1, "slice"),
            C(START_TICK, "z", 1, "value"),
            T(1, tasks.SubscriptAssign(), {
                'quick': True,
                'syncpoint': True
            }), C(START_TICK, "x", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 33
0
 def test_readglobal(self):
 
     def f():
         return __pydron_read_global__("TestTranslator")  #@UndefinedVariable
     
     expected = G(
         T(1, tasks.ConstTask("TestTranslator"), {'quick':True}),
         C(1, "value", 2, "var"),
         T(2, tasks.ReadGlobal(__name__), {'quick': True}),
         C(2, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
     
Ejemplo n.º 34
0
 def test_call_karg(self):
     
     def f(a,b,c):
         return a(foo=b, bar=c)
     
     expected = G(
         C(START_TICK, "a", 1, "func"),
         C(START_TICK, "b", 1, "karg_0"),
         C(START_TICK, "c", 1, "karg_1"),
         T(1, tasks.CallTask(0, ['foo', 'bar'], False, False), {'syncpoint':True}),
         C(1, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 35
0
 def test_augassign_attr(self):
     
     def f(a, b):
         a.myattr += b
         return a
         
     expected = G(
         C(START_TICK, "a", 1, "target"),
         C(START_TICK, "b", 1, "value"),
         T(1, tasks.AugAttrAssignTask(ast.Add(), "myattr"), {'quick':True, 'syncpoint':True}),
         C(START_TICK, "a", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 36
0
 def test_attribute_assign(self):
     
     def f(x, y):
         x.myattribute = y
         return x
         
     expected = G(
         C(START_TICK, "x", 1, "object"),
         C(START_TICK, "y", 1, "value"),
         T(1, tasks.AttrAssign("myattribute"), {'quick':True, 'syncpoint':True}),
         C(START_TICK, "x", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 37
0
 def test_subscript_assign(self):
     
     def f(x, y, z):
         x[y] = z
         return x
         
     expected = G(
         C(START_TICK, "x", 1, "object"),
         C(START_TICK, "y", 1, "slice"),
         C(START_TICK, "z", 1, "value"),
         T(1, tasks.SubscriptAssign(), {'quick':True, 'syncpoint':True}),
         C(START_TICK, "x", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 38
0
 def test_dict(self):
     
     def f(k1, v1, k2, v2):
         return {k1:v1, k2:v2}
     
     expected = G(
         C(START_TICK, "k1", 1, "key_0"),
         C(START_TICK, "v1", 1, "value_0"),
         C(START_TICK, "k2", 1, "key_1"),
         C(START_TICK, "v2", 1, "value_1"),
         T(1, tasks.DictTask(2), {'quick':True}),
         C(1, "value", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 39
0
 def test_augassign_subscript(self):
     
     def f(a, b, i):
         a[i] += b
         return a
         
     expected = G(
         C(START_TICK, "a", 1, "target"),
         C(START_TICK, "b", 1, "value"),
         C(START_TICK, "i", 1, "slice"),
         T(1, tasks.AugSubscriptAssignTask(ast.Add()), {'quick':True, 'syncpoint':True}),
         C(START_TICK, "a", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 40
0
    def test_nested_FunctionDef(self):
        
        def f():
            def g():
                return None
            return g

        expected = G(
            T(1, tasks.FunctionDefTask("scheduler", 'g', [], None, None, 0, G(
                T(1, tasks.ConstTask(None), {'quick':True}),
                C(1, "value", FINAL_TICK, "retval")
            )), {'quick':True}),
            C(1, "function", FINAL_TICK, "retval")
        )
   
        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 41
0
 def test_raise(self):
     
     def f(x):
         raise x
         return x
     
     expected = G(
         T(1, tasks.ConstTask(None), {'quick':True}),
         C(1, "value", 2, "inst"),
         C(START_TICK, "x", 2, "type"),
         C(1, "value", 2, "tback"),
         T(2, tasks.RaiseTask(), {'quick':True}),
         C(START_TICK, "x", FINAL_TICK, "retval")      
     )
     
     callee = translator.translate_function(f, "scheduler", False)
     utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 42
0
    def test_nested_FunctionDef(self):
        def f():
            def g():
                return None

            return g

        expected = G(
            T(
                1,
                tasks.FunctionDefTask(
                    "scheduler", 'g', [], None, None, 0,
                    G(T(1, tasks.ConstTask(None), {'quick': True}),
                      C(1, "value", FINAL_TICK, "retval"))), {'quick': True}),
            C(1, "function", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 43
0
    def test_while(self):
        
        def f(x):
            while x:
                pass
            return x
            
        with graph_factory():
            expected = G(
              C(START_TICK, "x", 1, "$test"),
              C(START_TICK, "x", 1, "x"),
              T(1, tasks.WhileTask(False, False, G("body",
                  C(START_TICK, "x", 1 , "$test"),
                  C(START_TICK, "x", 1 , "x"),
                  T(1, tasks.WhileTask(True, False, G("body"), G("else"))),
              ), G("else"))),
              C(START_TICK, "x", FINAL_TICK, "retval")
            )

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 44
0
    def test_if_inputs(self):
        def f():
            t = True
            c = 42
            if t:
                x = c
            else:
                x = c
            return x

        expected = G(
            T(1, tasks.ConstTask(True), {'quick': True}),
            T(2, tasks.ConstTask(42), {'quick': True}),
            C(1, "value", 3, "$test"), C(2, "value", 3, "c"),
            T(
                3,
                tasks.IfTask(G(C(START_TICK, "c", FINAL_TICK, "x")),
                             G(C(START_TICK, "c", FINAL_TICK, "x")))),
            C(3, "x", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 45
0
    def test_if(self):
        def f():
            t = True
            if t:
                x = 1
            else:
                x = 2
            return x

        expected = G(
            T(1, tasks.ConstTask(True), {'quick': True}),
            C(1, "value", 2, "$test"),
            T(
                2,
                tasks.IfTask(
                    G(T(1, tasks.ConstTask(1), {'quick': True}),
                      C(1, "value", FINAL_TICK, "x")),
                    G(T(1, tasks.ConstTask(2), {'quick': True}),
                      C(1, "value", FINAL_TICK, "x")))),
            C(2, "x", FINAL_TICK, "retval"))

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 46
0
    def test_while_break(self):
        
        def f(x):
            while x:
                if True:
                    break
            return x
            
        with graph_factory():
            expected = G(
              C(START_TICK, "x", 1, "$test"),
              C(START_TICK, "x", 1, "x"),
              T(1, tasks.WhileTask(False, False, G("body",
                  C(START_TICK, "x", 2 , "$test"),
                  C(START_TICK, "x", 2 , "x"),
                  T(1, tasks.ConstTask(True), {'quick':True}),
                  C(1, "value", 2, "$breaked"),
                  T(2, tasks.WhileTask(True, True, G("body"), G("else"))),
              ), G("else"))),
              C(START_TICK, "x", FINAL_TICK, "retval")
            )

        callee = translator.translate_function(f, "scheduler", False)
        utils.assert_graph_equal(expected, callee.graph)
Ejemplo n.º 47
0
 def call(*args, **kwargs):
     dataflowcallable = translator.translate_function(
         f, blocking.BlockingScheduler())
     return dataflowcallable(*args, **kwargs)
Ejemplo n.º 48
0
 def call(*args, **kwargs):
     dataflowcallable = translator.translate_function(f, blocking.BlockingScheduler())
     return dataflowcallable(*args, **kwargs)