예제 #1
0
파일: test_node.py 프로젝트: gangtao/pyflow
    def test_node_multiple_output(self):
        spec = '''
        {
            "title" : "node_exchange",
            "id" : "my.test.node.exchange",
            "port" : {
                "input" : [
                        {"name" : "port1", "order" : 0},
                        {"name" : "port2", "order" : 1}
                    ],
                    "output" : [
                        {"name" : "out1" },
                        {"name" : "out2" }
                    ]
                },
            "func" : "def func(x,y):
                ret = {}
                ret[\\"out2\\"] = x  ## Using ' or \\" here to avoid JSON decoding error
                ret[\\"out1\\"] = y
                return ret"
        }
        '''

        spec_obj = json.loads(spec, strict=False)

        anode = Node("my.test.node2", "node2", spec_obj)

        anode.set_inport_value("port1", "goto2")
        anode.set_inport_value("port2", "goto1")
        anode.run()

        self.assertEqual(anode.get_outport_value("out1"), "goto1")
        self.assertEqual(anode.get_outport_value("out2"), "goto2")
예제 #2
0
파일: test_node.py 프로젝트: gangtao/pyflow
    def test_node(self):
        spec = '''
        {
          "title" : "node_plus",
          "id" : "my.test.node.plus",
          "port" : {
                "input" : [
                    {"name" : "port1", "order" : 0},
                    {"name" : "port2", "order" : 1}
                ]
            },
          "func" : "def func(x,y):
            return x + y"
        }
        '''

        spec_obj = json.loads(spec, strict=False)

        anode = Node("my.test.node1", "node1", spec_obj)

        anode.set_inport_value("port1", "x")
        anode.set_inport_value("port2", "y")
        anode.run()

        self.assertEqual(anode.get_outport_value(), "xy")

        anode.set_inport_value("port1", 1)
        anode.set_inport_value("port2", 2)
        anode.run()

        self.assertEqual(anode.get_outport_value(), 3)
예제 #3
0
    def test_node_multiple_output(self):
        spec = '''
        {
            "title" : "node_exchange",
            "id" : "my.test.node.exchange",
            "port" : {
                "input" : [
                        {"name" : "port1", "order" : 0},
                        {"name" : "port2", "order" : 1}
                    ],
                    "output" : [
                        {"name" : "out1" },
                        {"name" : "out2" }
                    ]
                },
            "func" : "def func(x,y):
                ret = {}
                ret[\\"out2\\"] = x  ## Using ' or \\" here to avoid JSON decoding error
                ret[\\"out1\\"] = y
                return ret"
        }
        '''

        spec_obj = json.loads(spec, strict=False)

        anode = Node("my.test.node2", "node2", spec_obj)

        anode.set_inport_value("port1", "goto2")
        anode.set_inport_value("port2", "goto1")
        anode.run()

        self.assertEqual(anode.get_outport_value("out1"), "goto1")
        self.assertEqual(anode.get_outport_value("out2"), "goto2")
예제 #4
0
    def test_node(self):
        spec = '''
        {
          "title" : "node_plus",
          "id" : "my.test.node.plus",
          "port" : {
                "input" : [
                    {"name" : "port1", "order" : 0},
                    {"name" : "port2", "order" : 1}
                ]
            },
          "func" : "def func(x,y):
            return x + y"
        }
        '''

        spec_obj = json.loads(spec, strict=False)

        anode = Node("my.test.node1", "node1", spec_obj)

        anode.set_inport_value("port1", "x")
        anode.set_inport_value("port2", "y")
        anode.run()

        self.assertEqual(anode.get_outport_value(), "xy")

        anode.set_inport_value("port1", 1)
        anode.set_inport_value("port2", 2)
        anode.run()

        self.assertEqual(anode.get_outport_value(), 3)
예제 #5
0
파일: test_flow.py 프로젝트: gangtao/pyflow
    def test_flow_3nodes(self):
        aflow = Flow("my.test.aflow", "A flow test")

        spec = '''
        {
          "title" : "node_plus",
          "id" : "my.test.node.plus",
          "port" : {
                "input" : [
                    {"name" : "port1", "order" : 0},
                    {"name" : "port2", "order" : 1}
                ]
            },
          "func" : "def func(x,y):
            return x + y"
        }
        '''

        spec_obj = json.loads(spec, strict=False)

        node1 = Node("my.test.node1", "node1", spec_obj)
        node2 = Node("my.test.node2", "node1", spec_obj)
        node3 = Node("my.test.node3", "node3", spec_obj)

        aflow.add_node(node1)
        aflow.add_node(node2)
        aflow.add_node(node3)

        aflow.link(node1.id, "out", node3.id, "port1")
        aflow.link(node2.id, "out", node3.id, "port2")

        node1.set_inport_value("port1", "A")
        node1.set_inport_value("port2", "B")
        node2.set_inport_value("port1", "C")
        node2.set_inport_value("port2", "D")

        stats = aflow.run(node3)

        while not stats.check_stat():
            time.sleep(0.1)

        result = stats.get_result_by_id("my.test.node3")
        self.assertEqual(result["outputs"][0]["value"], "ABCD")
예제 #6
0
    def test_flow_3nodes(self):
        aflow = Flow("my.test.aflow", "A flow test")

        spec = '''
        {
          "title" : "node_plus",
          "id" : "my.test.node.plus",
          "port" : {
                "input" : [
                    {"name" : "port1", "order" : 0},
                    {"name" : "port2", "order" : 1}
                ]
            },
          "func" : "def func(x,y):
            return x + y"
        }
        '''

        spec_obj = json.loads(spec, strict=False)

        node1 = Node("my.test.node1", "node1", spec_obj)
        node2 = Node("my.test.node2", "node1", spec_obj)
        node3 = Node("my.test.node3", "node3", spec_obj)

        aflow.add_node(node1)
        aflow.add_node(node2)
        aflow.add_node(node3)

        aflow.link(node1.id, "out", node3.id, "port1")
        aflow.link(node2.id, "out", node3.id, "port2")

        node1.set_inport_value("port1", "A")
        node1.set_inport_value("port2", "B")
        node2.set_inport_value("port1", "C")
        node2.set_inport_value("port2", "D")

        stats = aflow.run(node3)

        while not stats.check_stat():
            time.sleep(0.1)

        result = stats.get_result_by_id("my.test.node3")
        self.assertEqual(result["outputs"][0]["value"], "ABCD")