コード例 #1
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)
コード例 #2
0
    def test_nested_task(self):
        pkg=PackageSource('testpkg', 'pkgfile', 'NONE')
        exec_task = ExecTask("exec_name", pkg, ('a',), ('b',))
        subgraph =  G(
            C(START_TICK, 'a', 1,'a'),
            C(START_TICK, 'context', 1,'context'),
            T(1, exec_task, {'name': 'test_exec', 'path':'test_exec'}),
            C(1, 'b', FINAL_TICK,'b'),
        )
        
        subgraph_task_tick=subgraph.get_all_ticks()[0]
        graph=Graph()
        task=NestedGraphTask(subgraph, 'test_nested')
        tick=START_TICK+1
        graph.add_task(tick, task, {'name':'test_nested','path':'test_nested'})
        source=Endpoint(START_TICK, 'a')
        dest=Endpoint(tick, 'a')
        graph.connect(source,dest)
        source=Endpoint(START_TICK, 'context')
        dest=Endpoint(tick, 'context')
        graph.connect(source,dest)
        source=Endpoint(tick, 'b')
        dest=Endpoint(FINAL_TICK, 'b')
        graph.connect(source,dest)

        task.refine(graph, Tick.parse_tick(1), {'context':{},'a':{}})

        expected_graph_task_tick=subgraph_task_tick<<Tick.parse_tick(1)        
        expected =  G(
            C(START_TICK, 'a', expected_graph_task_tick,'a'),
            C(START_TICK, 'context', expected_graph_task_tick,'context'),
            T(expected_graph_task_tick, exec_task, {'name': 'test_exec', 'path':'test_nested.test_exec'}),
            C(expected_graph_task_tick, 'b', FINAL_TICK,'b'),
        )
        utils.assert_graph_equal(expected, graph)
コード例 #3
0
 def test_refine(self):
     
     # t = True
     # if t:
     #     x = 1
     # else:
     #     x = 2
     # return x
     
     g = G(
         T(1, tasks.ConstTask(True)),
         C(1, "value", 2, "$test"),
         T(2, tasks.IfTask(G(
             T(1, tasks.ConstTask(1)),
             C(1, "value", FINAL_TICK, "x")
         ), G(
             T(1, tasks.ConstTask(2)),
             C(1, "value", FINAL_TICK, "x")
         ))),
         C(2, "x", FINAL_TICK, "retval")
     )
     
     target = g.get_task(START_TICK + 2)
     target.refine(g, START_TICK + 2, {"$test":True})
     
     expected = G(
         T(1, tasks.ConstTask(True)),
         T((2,1), tasks.ConstTask(1)),
         C((2,1), "value", FINAL_TICK, "retval")
     )
     
     utils.assert_graph_equal(expected, g)
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
    def test_simple_task(self):
        """
        A simple one-step pipeline 
        """
        def testpipe(x,y):
            u,v=test_exec(a=x, b=y)
            return u,v
        
        graph=build_graph(testpipe)
        self.assertTrue(isinstance(graph,Graph))
        
        # there is just a single task - hence just a single node / tick
        self.assertEqual(1, len(graph.get_all_ticks()))
        task=graph.get_task(graph.get_all_ticks()[0])
        self.assertTrue(isinstance(task,ExecTask))
        self.assertEqual('test_exec',task.command)
        self.assertEqual(set(['a','b']),set(task.inputnames))
        self.assertEqual(set(['c','d']),set(task.outputnames))

        expected =  G(
            C(START_TICK, 'a', 1,'a'),
            C(START_TICK, 'b', 1,'b'),
            C(START_TICK, 'context', 1,'context'),
            T(1, task, {'name': 'test_exec', 'path':'test_exec'}),
            C(1, 'c', FINAL_TICK,'test_exec.c'),
            C(1, 'd', FINAL_TICK,'test_exec.d')
        )
        expected.set_task_property(FINAL_TICK,'aliases', 
            {'test_exec.c':'test_exec.c', 'test_exec.d':'test_exec.d'})
        
        utils.assert_graph_equal(expected, graph)
コード例 #7
0
 def test_unassigned_out(self):
     
     subgraph = G(
         C(START_TICK, "sin", 1, "x"),
         T(1, "subtask"),
         C(1, "y", FINAL_TICK, "sout")
     )
     
     g = G(
           C(START_TICK, "in", 1, "sin"),
           C(START_TICK, "sout2", 1, "sout2"),
           T(1, "task_to_replace"),
           C(1, "sout", FINAL_TICK, "out"),
           C(1, "sout2", FINAL_TICK, "out2")
           )
     
     expected  = G(
           C(START_TICK, "in", (1,1), "x"),
           T((1,1), "subtask"),
           C((1,1), "y", FINAL_TICK, "out"),
           C(START_TICK, "sout2", FINAL_TICK, "out2")
           )
     
     refine.replace_task(g, START_TICK + 1, subgraph)
     
     utils.assert_graph_equal(expected, g)
コード例 #8
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)
コード例 #9
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)
コード例 #10
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)
コード例 #11
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)
コード例 #12
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)
コード例 #13
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)
コード例 #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)
コード例 #15
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)
コード例 #16
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)
コード例 #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)
コード例 #18
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)
コード例 #19
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)
コード例 #20
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)
コード例 #21
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)
コード例 #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)
コード例 #23
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)
コード例 #24
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)
コード例 #25
0
    def test_mocking(self):
        self.target.add_task(START_TICK + 100, "task1", {'nicename':'test1'})
        self.target.add_task(START_TICK + 101, "task2", {'nicename':'test2'})
        self.target.connect(graph.Endpoint(START_TICK + 100, 'out'), 
                            graph.Endpoint(START_TICK + 101, 'in'))
        
        expected =  G(
            T(100, 'task1', {'nicename': 'test1'}),
            C(100, 'out', 101, 'in'),
            T(101, 'task2', {'nicename': 'test2'}),
        )

        utils.assert_graph_equal(expected, self.target)
コード例 #26
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)
コード例 #27
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)
コード例 #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)
コード例 #29
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)
コード例 #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)
コード例 #31
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)
コード例 #32
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)
コード例 #33
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)
コード例 #34
0
ファイル: test_tasks.py プロジェクト: mahmoudimus/pydron
    def test_refine_body_break(self):
        # def f(lst, x):
        #     for x in lst:
        #         if True:
        #            break
        #     return x
            
        with graph_factory():
            g = G(
              C(START_TICK, "lst", 1, "iterable"),
              T(1, tasks.IterTask()),
              C(1, "value", 2, "$iterator"),
              C(START_TICK, "x", 2, "x"),
              T(2, tasks.ForTask(False, False, G("body",
                  T(1, tasks.ConstTask(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")
            )

            
        target = g.get_task(START_TICK + 2)
        target.refine(g, START_TICK + 2, {"$iterator":iter([1,2,3])})
        
        with graph_factory():
            expected = G(
              C(START_TICK, "lst", 1, "iterable"),
              T(1, tasks.IterTask()),
              C(1, "value", (2,1,2,2), "$iterator"),
              T((2,1,1), tasks.ConstTask(1)),
              T((2,1,2,1), tasks.ConstTask(True)),
              C((2,1,1), "value", (2,1,2,2), "x"),
              C((2,1,2,1), "value", (2,1,2,2), "$breaked"),
              T((2,1,2,2), tasks.ForTask(True, True, G("body",
                  T(1, tasks.ConstTask(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,1,2,2), "x", FINAL_TICK, "retval")
            )
            
        utils.assert_graph_equal(expected, g)
コード例 #35
0
ファイル: test_tasks.py プロジェクト: mahmoudimus/pydron
 def test_refine_body_twice(self):
     # def f(lst, x):
     #     for x in lst:
     #         pass
     #     return x
         
     with graph_factory():
         g = G(
           C(START_TICK, "lst", 1, "iterable"),
           T(1, tasks.IterTask()),
           C(1, "value", 2, "$iterator"),
           C(START_TICK, "x", 2, "x"),
           T(2, tasks.ForTask(False, False, G("body",
               C(START_TICK, "$target",1 , "x"),
               C(START_TICK, "$iterator", 1, "$iterator"),
               T(1, tasks.ForTask(True, False, G("body"), G("else"))),
               C(1, "x", FINAL_TICK, "x")
           ), G("else"))),
           C(2, "x", FINAL_TICK, "retval")
         )
         
     it = iter([1,2,3])
     
     target_tick = START_TICK + 2
     target = g.get_task(target_tick)
     target.refine(g, target_tick, {"$iterator":it})
     
     target_tick = Tick.parse_tick((2,1,2,1))
     target = g.get_task(target_tick)
     target.refine(g, target_tick, {"$iterator":it})                
     
     with graph_factory():
         expected = G(
           C(START_TICK, "lst", 1, "iterable"),
           T(1, tasks.IterTask()),
           T((2,1,1), tasks.ConstTask(1)),
           T((2,2,1), tasks.ConstTask(2)),
           C(1, "value", (2,2,2,1), "$iterator"),
           C((2,2,1), "value", (2,2,2,1), "x"),
           T((2,2,2,1), tasks.ForTask(True, False, G("body",
               C(START_TICK, "$target",1 , "x"),
               C(START_TICK, "$iterator", 1, "$iterator"),
               T(1, tasks.ForTask(True, False, G("body"), G("else"))),
               C(1, "x", FINAL_TICK, "x")
           ), G("else"))),
           C((2,2,2,1), "x", FINAL_TICK, "retval")
         )
         
     utils.assert_graph_equal(expected, g)
コード例 #36
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)
コード例 #37
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)
     
コード例 #38
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)
コード例 #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)
コード例 #40
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)
コード例 #41
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)
コード例 #42
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)
コード例 #43
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)
コード例 #44
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)
コード例 #45
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)
コード例 #46
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)
コード例 #47
0
    def test_nested(self):
        
        graph = build_graph(testpipe_nested)

        # there are two tasks
        self.assertEqual(1, len(graph.get_all_ticks()))
        nested=graph.get_task(graph.get_all_ticks()[0])

        self.assertTrue(isinstance(nested,NestedGraphTask))
        self.assertEqual('test_task_nested',nested.name)

        task1=ExecTask('test_exec', Package('test'), ['a','b'], ['c','d'])
        task2=ExecTask('test_exec', Package('test'), ['a','b'], ['c','d'])

        subgraph =  G(
            C(START_TICK, 'a', 1,'a'),
            C(START_TICK, 'b', 1,'b'),
            C(START_TICK, 'context', 1,'context'),
            C(START_TICK, 'context', 2,'context'),
            T(1, task1, {'name': 'test_exec', 'path':'test_exec'}),
            C(1, 'c', 2, 'a'),
            C(1, 'd', 2, 'b'),
            T(2, task2, {'name': 'test_exec2', 'path':'test_exec2'}),
            C(1, 'c', FINAL_TICK,'test_exec.c'),
            C(2, 'c', FINAL_TICK,'test_exec2.c'),
            C(2, 'd', FINAL_TICK,'test_exec2.d')
        )
        subgraph.set_task_property(FINAL_TICK,'aliases', 
            {'test_exec.c':'test_exec.c', 'test_exec2.c':'test_exec2.c', 'test_exec2.d':'test_exec2.d'})
        utils.assert_graph_equal(subgraph, nested.body_graph)
        
        expected =  G(
            C(START_TICK, 'x', 1,'x'),
            C(START_TICK, 'y', 1,'y'),
            C(START_TICK, 'context', 1,'context'),
            T(1, nested, {'name': 'test_task_nested', 'path':'test_task_nested'}),
            C(1, 'test_exec.c', FINAL_TICK,'test_task_nested.test_exec.c'),
            C(1, 'test_exec2.c', FINAL_TICK,'test_task_nested.test_exec2.c'),
            C(1, 'test_exec2.d', FINAL_TICK,'test_task_nested.test_exec2.d')
        )
        expected.set_task_property(FINAL_TICK,'aliases',
            {'test_task_nested.test_exec.c':'test_task_nested.test_exec.c', 
             'test_task_nested.test_exec2.c':'test_task_nested.test_exec2.c',
             'test_task_nested.test_exec2.d':'test_task_nested.test_exec2.d'})

        utils.assert_graph_equal(expected, graph)
コード例 #48
0
    def test_inline(self):

        def testpipe(x,y):
            return test_task(x=x,y=y)

        def test_task(x,y):
            u,v=test_exec(a=x, b=y)
            w,z=test_exec(name="test_exec2", a=u, b=v)
            return u,w,z
        
        graph = build_graph(testpipe)

        # there are two tasks
        self.assertEqual(2, len(graph.get_all_ticks()))
        ticks=sorted(graph.get_all_ticks())        
        task1=graph.get_task(ticks[0])
        task2=graph.get_task(ticks[1])

        self.assertTrue(isinstance(task1,ExecTask))
        self.assertEqual('test_exec',task1.command)
        self.assertEqual(set(['a','b']),set(task1.inputnames))
        self.assertEqual(set(['c','d']),set(task1.outputnames))

        self.assertTrue(isinstance(task2,ExecTask))
        self.assertEqual('test_exec',task2.command)
        self.assertEqual(set(['a','b']),set(task2.inputnames))
        self.assertEqual(set(['c','d']),set(task2.outputnames))

        expected =  G(
            C(START_TICK, 'a', 1,'a'),
            C(START_TICK, 'b', 1,'b'),
            C(START_TICK, 'context', 1,'context'),
            C(START_TICK, 'context', 2,'context'),
            T(1, task1, {'name': 'test_exec', 'path':'test_exec'}),
            C(1, 'c', 2, 'a'),
            C(1, 'd', 2, 'b'),
            T(2, task2, {'name': 'test_exec2', 'path':'test_exec2'}),
            C(1, 'c', FINAL_TICK,'test_exec.c'),
            C(2, 'c', FINAL_TICK,'test_exec2.c'),
            C(2, 'd', FINAL_TICK,'test_exec2.d')
        )
        expected.set_task_property(FINAL_TICK,'aliases', 
            {'test_exec.c':'test_exec.c', 'test_exec2.c':'test_exec2.c', 'test_exec2.d':'test_exec2.d'})
        
        utils.assert_graph_equal(expected, graph)
コード例 #49
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)
コード例 #50
0
    def test_nested_task(self):
        pkg = PackageSource('testpkg', 'pkgfile', 'NONE')
        exec_task = ExecTask("exec_name", pkg, ('a', ), ('b', ))
        subgraph = G(
            C(START_TICK, 'a', 1, 'a'),
            C(START_TICK, 'context', 1, 'context'),
            T(1, exec_task, {
                'name': 'test_exec',
                'path': 'test_exec'
            }),
            C(1, 'b', FINAL_TICK, 'b'),
        )

        subgraph_task_tick = subgraph.get_all_ticks()[0]
        graph = Graph()
        task = NestedGraphTask(subgraph, 'test_nested')
        tick = START_TICK + 1
        graph.add_task(tick, task, {
            'name': 'test_nested',
            'path': 'test_nested'
        })
        source = Endpoint(START_TICK, 'a')
        dest = Endpoint(tick, 'a')
        graph.connect(source, dest)
        source = Endpoint(START_TICK, 'context')
        dest = Endpoint(tick, 'context')
        graph.connect(source, dest)
        source = Endpoint(tick, 'b')
        dest = Endpoint(FINAL_TICK, 'b')
        graph.connect(source, dest)

        task.refine(graph, Tick.parse_tick(1), {'context': {}, 'a': {}})

        expected_graph_task_tick = subgraph_task_tick << Tick.parse_tick(1)
        expected = G(
            C(START_TICK, 'a', expected_graph_task_tick, 'a'),
            C(START_TICK, 'context', expected_graph_task_tick, 'context'),
            T(expected_graph_task_tick, exec_task, {
                'name': 'test_exec',
                'path': 'test_nested.test_exec'
            }),
            C(expected_graph_task_tick, 'b', FINAL_TICK, 'b'),
        )
        utils.assert_graph_equal(expected, graph)
コード例 #51
0
 def test_passhtrough(self):
     
     subgraph = G(
         C(START_TICK, "sin", FINAL_TICK,"sout"),
     )
     
     g = G(
           C(START_TICK, "in", 1, "sin"),
           T(1, "task_to_replace"),
           C(1, "sout", FINAL_TICK, "out"),
           )
     
     expected  = G(
           C(START_TICK, "in", FINAL_TICK, "out"),
           )
     
     refine.replace_task(g, START_TICK + 1, subgraph)
     
     utils.assert_graph_equal(expected, g)
     
コード例 #52
0
ファイル: test_tasks.py プロジェクト: mahmoudimus/pydron
 def test_refine_body_twice(self):
     # def f(x):
     #     while x:
     #         pass
     #     return x
         
     with graph_factory():
         g = 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")
         )
         
         
     target = g.get_task(START_TICK + 1)
     target.refine(g, START_TICK + 1, {"$test":True})
     
     target = g.get_task(Tick.parse_tick((1,1,1)))
     target.refine(g, Tick.parse_tick((1,1,1)), {"$test":True})
     
     with graph_factory():
         expected = G(
           C(START_TICK, "x", (1,2,1), "$test"),
           C(START_TICK, "x", (1,2,1), "x"),
           T((1,2,1), tasks.WhileTask(True, 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")
         )
         
         
     utils.assert_graph_equal(expected, g)
コード例 #53
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)