Пример #1
0
    def test_engine_multi_entry_point(self):
        engine = Engine("op1", "op2")
        engine.op1.setup(in_name="in1", out_name="middle", required=False)
        engine.op2.setup(in_name="middle", out_name="out")
        engine.op1.append(self.mult_opt)
        engine.op2.append(self.plus_comp)

        # should run all the blocks
        engine.op1.select("mult_opt")
        res = engine.play(10)
        assert res["out"] == 52
        assert res["middle"] == 50
        # should be possible to named the input of the 1st block
        res = engine.play(in1=10)
        assert res["out"] == 52
        assert res["middle"] == 50

        # should need input 'in'
        with self.assertRaises(ReliureError):
            res = engine.play(middle=10)

        # should not be possible to give to many inputs
        with self.assertRaises(ReliureError):
            res = engine.play(middle=10, in1=10)

        # should be possible to not play the op1 block
        engine.op1.clear_selections()
        res = engine.play(middle=10)
        assert len(res) == 2
        assert res["middle"] == 10
        assert res["out"] == 12
Пример #2
0
    def test_engine_named_inout_multiin(self):
        # a block should work with multiple inputs
        engine = Engine("op1", "op2", "op3")
        
        engine.op1.set(self.mult_opt)
        engine.op1.setup(in_name="in1", out_name="out1")
        engine.op2.set(self.plus_comp)
        engine.op2.setup(in_name="in1", out_name="out2")
        engine.op3.set(MinusTwoInputs())
        engine.op3.setup(in_name=["out1", "out2"], out_name="out3")

        res = engine.play(3) # (mult * 5) - (3 + 2)
        assert res['in1'] == 3
        assert res['out1'] == 3*5
        assert res['out2'] == 3+2
        assert res['out3'] == (3*5) - (3+2)

        # it should be possible to have a multi in as first component !
        engine = Engine("op3")
        engine.op3.set(MinusTwoInputs())
        engine.op3.setup(in_name=["in1", "in2"], out_name="out")
        res = engine.play(3, 40)
        assert res['out'] == -37

        # it should not validate if multiple data are not present
        engine = Engine("op1", "op3")
        engine.op1.set(self.mult_opt)
        engine.op1.setup(in_name="in1", out_name="out1")
        engine.op3.set(MinusTwoInputs())
        engine.op3.setup(in_name=["out1", "out2"], out_name="out3")

        with self.assertRaises(ReliureError):
            engine.validate()
Пример #3
0
    def test_engine_multi_entry(self):
        engine = Engine("op1", "op2")

        engine.op1.set(self.mult_opt)
        engine.op1.setup(in_name="in1", out_name="middle")
        engine.op2.set(MinusTwoInputs())
        engine.op2.setup(in_name=["in2", "middle"], out_name="out")

        # an input is missing
        with self.assertRaises(ReliureError):
            res = engine.play(10)

        res = engine.play(in1=10, in2=2)
        assert len(res) == 4
        assert res["middle"] == 50
        assert res["out"] == -48
Пример #4
0
    def test_engine_default_pipeline(self):
        engine = Engine("op1", "op2", "op3")
        # should have a __len__
        assert len(engine) == 3
        # should have a __contains__
        assert "op1" in engine
        assert "op2" in engine
        assert "op3" in engine
        assert not "op4" in engine
        # should not be possible to require a block that do not exist
        with self.assertRaises(ReliureError):
            engine.requires("op4")
        # should be possible to set the component for each block
        engine.op1.set(self.mult_opt)
        # but not on non existing blocks 
        with self.assertRaises(ValueError):
            engine.op4.set(self.mult_opt)
        with self.assertRaises(ValueError):
            engine["op4"].set(self.mult_opt)
        with self.assertRaises(ValueError):
            engine.set("op4", self.mult_opt)
        
        # should not validate if there is no component for all blocks
        with self.assertRaises(ReliureError):
            engine.validate()

        #should be posisble to 'append' a possible component to the block
        engine.op2.append(self.mult_opt)
        # and to set is as default in the same time
        engine.op2.append(self.plus_comp, default=True)
        
        # should be possible to select on component
        engine.op1.select("mult_opt")

        # should be possible to know if one block is multiple
        assert not engine.op2.multiple
        # to know wich component will be run
        assert engine.op2.selected() == ["plus_comp"]
        # to play just one block !
        assert engine.op2.play(10) == {'op2': 12}

        # and then is should validate is every block has som components
        engine.set("op3", self.mult_opt, self.plus_comp, self.max_comp)
        engine.validate()

        # should play !
        res = engine.play(3) # mult * 5 | + 2 | mult
        # and all intermediare results should be available
        assert res['input'] == 3
        assert res['op1'] == 3*5
        assert res['op2'] == 3*5+2
        assert res['op3'] == (3*5+2)*5
Пример #5
0
    def test_engine_named_inout_pipeline(self):
        engine = Engine("op1", "op2", "op3")
        
        engine.op1.set(self.mult_opt)
        engine.op1.setup(in_name="in1", out_name="out1")

        engine.op2.set(self.plus_comp)
        engine.op2.setup(in_name="out1", out_name="out2")

        engine.op3.set(self.mult_opt)
        engine.op3.setup(in_name="out2", out_name="out3")

        res = engine.play(3) # mult * 5 | + 2 | mult
        assert res['in1'] == 3
        assert res['out1'] == 3*5
        assert res['out2'] == 3*5+2
        assert res['out3'] == (3*5+2)*5