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
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'}] })