Exemple #1
0
    def test_configure_errors(self):
        # Should raise valueError when configuration is not valit
        engine = Engine("op1", "op2", "op3")
        engine.set("op1", self.mult_opt, self.plus_comp, self.max_comp)
        engine.set("op2", self.plus_comp, self.mult_opt, self.max_comp)
        engine.op2.setup(hidden=True)
        engine.set("op3", self.mult_opt, self.plus_comp, self.max_comp)

        with self.assertRaises(ValueError): # op2 hidden it can be configured
            engine.configure({
                'op2':{'name': 'max20'}
            })
        with self.assertRaises(ValueError): # 'maxmax' doesn't exist
            engine.configure({
                'op3':{'name': 'maxmax'}
            })
        with self.assertRaises(ValueError): # error in op1 format
            engine.configure({
                'op1':{'namss': 'mult'}
            })
        with self.assertRaises(ValueError): # block doesn't exist
            engine.configure({
                'op5':{'name': 'max20'}
            })
        with self.assertRaises(ValueError): # block required !
            engine.configure({
                'op1':[]
            })
        with self.assertRaises(ValueError): # block not multi !
            engine.configure({
                'op1':[{'name': 'max20'}, {'name': 'plus_comp'}]
            })
Exemple #2
0
    def test_configure(self):
        engine = Engine("op1", "op2")
        engine.set("op1", self.plus_comp, self.mult_opt, self.max_comp)
        engine.set("op2", self.plus_comp)

        assert engine.op1["mult_opt"].get_option_value("factor") == 5
        engine.configure({
            'op1':{
                'name': 'mult_opt',
                'options': {
                    'factor': '10'
                }
            },
            'op2':{
                'name': 'plus_comp'
            }
        })
        assert engine.op1.selected() == ["mult_opt"]
        assert engine.op1["mult_opt"].get_option_value("factor") == 10
        assert engine.op1.play(5) == {'op1': 50}
        
        # A new call to configure should reset the default values
        engine.configure({})    #this should reset the selected/options to default state
        assert engine.op1.selected() == ["plus_comp"]
        assert engine.op1["mult_opt"].get_option_value("factor") == 5
Exemple #3
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
Exemple #4
0
 def test_as_dict(self):
     engine = Engine("op1", "op2")
     engine.set("op1", self.plus_comp, self.mult_opt, self.max_comp)
     engine.set("op2", self.plus_comp)
     assert engine.as_dict() == {
         'args': ['input'],
         'blocks': [
             {
                 'components': [
                     {
                         'default': True,       #This is the default NOT the selected value
                         'name': 'plus_comp',
                         'options': None
                     },
                     {
                         'default': False,
                         'name': 'mult_opt',
                         'options': [
                             {
                                 'name': 'factor',
                                 'type': 'value',
                                 'value': 5,
                                 'otype': {
                                     'choices': None,
                                     'default': 5,
                                     'help': 'multipliation factor',
                                     'max': None,
                                     'min': None,
                                     'multi': False,
                                     'type': 'Numeric',
                                     'uniq': False,
                                     'vtype': 'int'
                                 }
                            }
                         ]
                     },
                     {
                         'name': 'max20',
                         'default': False,
                         'options': None
                     }
                 ],
                  'args': None,
                  'multiple': False,
                  'name': 'op1',
                  'returns': 'op1',
                  'required': True
             },
             {
                 'components': [
                      {
                          'name': 'plus_comp',
                          'default': True,
                          'options': None
                      }
                  ],
                  'args': None,
                  'multiple': False,
                  'name': 'op2',
                  'returns': 'op2',
                  'required': True
              }
         ]
     }