예제 #1
0
    def test_executor_transformer(self):
        with SimpleExecutor() as executor:
            with Graph("test") as graph:
                root = ast.parse(code)
                transformer = Transformer(globals())
                transformer.visit(root)

                x, y = executor.run(graph,
                                    inputs_tuple=([2], [1]),
                                    inputs_map={})
                self.assertEqual(x, 3)
                self.assertEqual(y, 0)
예제 #2
0
 def test_task_core(self):
     with Graph(name="test_graph") as graph:
         _a = EchoInputTask()
         _b = EchoNamedInputTask("b")
         _c = ConstantTask(1)
         _add = AddTask(_a, _b)
         _sub = SubTask(_a, _b)
         _mul = MulTask(_a, _b)
         _true_div = TrueDivTask(_a, _c)
         _floor_div = FloorDivTask(_a, _c)
         _return1 = EchoReturnTask(_add)
         _return2 = EchoReturnTask(_true_div)
         graph.show("result/test_task.gv")
예제 #3
0
    def test_simple_executor(self):
        with SimpleExecutor() as executor:
            with Graph(name="test") as graph:
                _int1 = InputTask(int)
                _int2 = NamedInputTask("int", int)
                _add = ReturnTask(add, _int1, _int2)
                _sub = ReturnTask(sub, _int1, _int2)
                _mul = ReturnTask(mul, _int1, _int2, execute="process")
                _div = ReturnTask(floordiv, _int1, _int2, execute="process")

                x, y, z, w = executor.run(graph,
                                          inputs_tuple=([2], ),
                                          inputs_map={"int": [1]})
                self.assertEqual(x, 3)
                self.assertEqual(y, 1)
                self.assertEqual(z, 2)
                self.assertEqual(w, 2)
예제 #4
0
    def test_executor_core(self):
        with SimpleExecutor() as executor:
            with Graph(name="test_graph") as graph:
                _a = EchoInputTask()
                _b = EchoNamedInputTask("b")
                _c = ConstantTask(1)
                _add = AddTask(_a, _b)
                _sub = SubTask(_a, _b)
                _mul = MulTask(_a, _b)
                _true_div = TrueDivTask(_a, _c)
                _floor_div = FloorDivTask(_a, _c)
                _return1 = EchoReturnTask(_add)
                _return2 = EchoReturnTask(_true_div)

                x, y = executor.run(graph,
                                    inputs_tuple=([2], ),
                                    inputs_map={"b": [1]})
                self.assertEqual(x, 3)
                self.assertEqual(y, 2)
예제 #5
0
import ast
from operator import add, sub, mul, floordiv
from task_flow import Graph, Transformer

code = """
def f(a, b):
    _int1 = int(a)
    _int2 = int(b)
    _add = add(_int1, _int2)
    _sub = sub(_int1, _int2)
    _mul = mul(_int1, _int2)
    _div = floordiv(_int1, _int2)
    print(_add, _sub, _mul, _div)
"""

if __name__ == "__main__":
    with Graph(name="test") as graph:
        env = globals()
        env["int"] = int
        env["print"] = print
        root = ast.parse(code)
        transformer = Transformer(env)
        transformer.visit(root)
        graph.show("result/test.gv")
예제 #6
0
 def test_task_transformer(self):
     with Graph("test") as graph:
         root = ast.parse(code)
         transformer = Transformer(globals())
         transformer.visit(root)
         graph.show("result/task.gv")