예제 #1
0
    def test_inOut(self):
        box1 = box.Box("global")
        box2 = conditionalBox.ConditionalBox("local")
        bl = Bool()
        make = MakeOne()
        dmp = Dump()
        plus = PlusOne()

        box1.addBlock(box2)
        box1.addBlock(bl)
        box1.addBlock(dmp)
        box1.addBlock(make)

        box2.addBlock(plus)
        workerManager.WorkerManager.SetUseProcess(False)
        in_p = box2.addInputProxy(int, "in")
        out_p = box2.addOutputProxy(int, "out")

        self.assertIsNotNone(proxy.ProxyChain(make.output(0), in_p.inPort()))
        self.assertIsNotNone(proxy.ProxyChain(in_p.outPort(), plus.input(0)))
        self.assertIsNotNone(proxy.ProxyChain(plus.output(0), out_p.inPort()))
        self.assertIsNotNone(proxy.ProxyChain(out_p.outPort(), dmp.input(0)))
        self.assertIsNotNone(chain.Chain(bl.output(0), box2.input(0)))

        schedules = box1.getSchedule()

        bl.param("do").set(False)
        workerManager.WorkerManager.RunSchedule(schedules)
        results = []
        while (not dmp.dmp.empty()):
            results.append(dmp.dmp.get())
        self.assertEqual(results, [])

        dmp.flush()
        bl.param("do").set(True)
        workerManager.WorkerManager.RunSchedule(schedules)
        results = []
        while (not dmp.dmp.empty()):
            results.append(dmp.dmp.get())
        self.assertEqual(results, [1])

        workerManager.WorkerManager.SetUseProcess(True)
        dmp.useProcess(True)

        bl.param("do").set(False)
        workerManager.WorkerManager.RunSchedule(schedules)
        results = []
        while (not dmp.dmp.empty()):
            results.append(dmp.dmp.get())
        self.assertEqual(results, [])

        dmp.flush()
        bl.param("do").set(True)
        workerManager.WorkerManager.RunSchedule(schedules)
        results = []
        while (not dmp.dmp.empty()):
            results.append(dmp.dmp.get())
        self.assertEqual(results, [1])
예제 #2
0
    def test_chain(self):
        box1 = box.Box("bigBox")
        box2 = box.Box("smallBox")
        num1 = MakeNumber()
        num2 = MakeNumber()
        doub1 = Double()
        doub2 = Double()
        add1 = Add()
        add2 = Add()

        box1.addBlock(box2)
        box1.addBlock(num1)
        box1.addBlock(num2)
        box2.addBlock(doub1)
        box2.addBlock(doub2)
        box1.addBlock(add1)
        box1.addBlock(add2)

        box2.addInputProxy(float, "in")
        box2.addOutputProxy(float, "out")

        self.assertIsNotNone(
            proxy.ProxyChain(num1.output(0), box2.inputProxyIn("in")))
        self.assertTrue(num1.output(0).isConnected())
        self.assertIsNotNone(
            proxy.ProxyChain(num2.output(0), box2.inputProxyIn("in")))
        self.assertFalse(num1.output(0).isConnected())
        self.assertTrue(num2.output(0).isConnected())

        self.assertIsNotNone(
            proxy.ProxyChain(box2.inputProxyOut("in"), doub1.input(0)))
        self.assertTrue(doub1.input(0).isConnected())
        self.assertIsNotNone(
            proxy.ProxyChain(box2.inputProxyOut("in"), doub2.input(0)))
        self.assertTrue(doub1.input(0).isConnected())
        self.assertTrue(doub2.input(0).isConnected())
        self.assertIsNotNone(
            proxy.ProxyChain(doub1.output(0), box2.outputProxyIn("out")))
        self.assertTrue(doub1.output(0).isConnected())
        self.assertIsNotNone(
            proxy.ProxyChain(doub2.output(0), box2.outputProxyIn("out")))
        self.assertFalse(doub1.output(0).isConnected())
        self.assertTrue(doub2.output(0).isConnected())

        self.assertIsNotNone(
            proxy.ProxyChain(box2.outputProxyOut("out"), add1.input(0)))
        self.assertTrue(add1.input(0).isConnected())
        self.assertIsNotNone((proxy.ProxyChain(box2.outputProxyOut("out"),
                                               add2.input(0))))
        self.assertTrue(add1.input(0).isConnected())
        self.assertTrue(add2.input(0).isConnected())
예제 #3
0
    def test_connect(self):
        box1 = box.Box("bigBox")
        box2 = box.Box("smallBox")
        in_prx = box2.addInputProxy(float, "inFloat")
        self.assertTrue(box2.hasInputProxy("inFloat"))
        out_prx = box2.addOutputProxy(float, "outFloat")
        self.assertTrue(box2.hasOutputProxy("outFloat"))
        num = MakeNumber()
        double = Double()
        dmp = DmpFloat()
        add = Add()

        box2.addBlock(double)
        box1.addBlock(num)
        box1.addBlock(dmp)
        box1.addBlock(box2)
        box1.addBlock(add)

        chain.Chain(add.output(0), dmp.input(0))

        self.assertIsNotNone(
            proxy.ProxyChain(box2.inputProxyOut("inFloat"), double.input(0)))
        self.assertIsNotNone(
            chain.Chain(double.output(0), box2.outputProxyIn("outFloat")))
        self.assertIsNotNone(
            chain.Chain(box2.outputProxyOut("outFloat"), dmp.input(0)))
        self.assertFalse(add.output(0).isConnected())
        self.assertIsNotNone(
            chain.Chain(add.output(0), box2.inputProxyIn("inFloat")))
        self.assertIsNotNone(
            proxy.ProxyChain(box2.outputProxyOut("outFloat"), add.input(0)))

        self.assertTrue(double.input(0).isConnected())
        self.assertTrue(double.output(0).isConnected())
        self.assertTrue(dmp.input(0).isConnected())
        self.assertTrue(add.input(0).isConnected())
        self.assertTrue(add.output(0).isConnected())
        self.assertIsNotNone(box2.inputProxyIn("inFloat"))
        self.assertIsNotNone(box2.outputProxyOut("outFloat"))
예제 #4
0
    def test_run(self):
        box1 = box.Box("bigBox")
        box2 = box.Box("smallBox")
        num = MakeNumber()
        double = Double()
        dmp = DmpFloat()
        add = Add()
        box1.addBlock(num)
        box1.addBlock(dmp)
        box1.addBlock(box2)
        box1.addBlock(add)
        box2.addBlock(double)

        box2.addInputProxy(float, "inFloat")
        box2.addOutputProxy(float, "outFloat")

        self.assertIsNotNone(
            proxy.ProxyChain(num.output(0), box2.inputProxyIn("inFloat")))
        self.assertIsNotNone(
            proxy.ProxyChain(box2.inputProxyOut("inFloat"), double.input(0)))
        self.assertIsNotNone(
            proxy.ProxyChain(double.output(0), box2.outputProxyIn("outFloat")))
        self.assertIsNotNone(
            proxy.ProxyChain(box2.outputProxyOut("outFloat"), add.input(0)))
        self.assertIsNotNone(chain.Chain(add.output(0), dmp.input(0)))

        workerManager.WorkerManager.SetUseProcess(True)
        workerManager.WorkerManager.RunSchedule(box1.getSchedule())

        vals = []
        for i in range(100):
            vals.append(float(i * 2) + 1)

        dmped = []
        while (not dmp.dmp.empty()):
            dmped.append(dmp.dmp.get())

        self.assertEqual(vals, dmped)