def __init__(self): self.pre_action_step = ActionStep() self.condition_step = ConditionStep() self.action_step = ActionStep() self.pre_action_step.set_next(self.condition_step) self.condition_step.set_evaluation(raw_input) self.condition_step.set_alternatives({'OK':self.action_step, 'CANCEL':None})
class NNFStep(object): def __init__(self): self.pre_action_step = ActionStep() self.condition_step = ConditionStep() self.action_step = ActionStep() self.pre_action_step.set_next(self.condition_step) self.condition_step.set_evaluation(raw_input) self.condition_step.set_alternatives({'OK':self.action_step, 'CANCEL':None}) def set_preaction(self, action, params=None): self.pre_action_step.set_action(action, params) def set_action(self, action, params=None): self.action_step.set_action(action, params) def set_evaluation(self, action, params=None): self.condition_step.set_evaluation(action, params) def evaluate(self): self.condition_step.evaluate() def act(self): self.action_step.act() def pre_act(self): self.pre_action_step.act() def set_next(self, step): self.action_step.set_next(step)
def test_case_1(): ''' sample workflow with actions and decisions (attached) ''' workflow = WorkFlow() step1 = ActionStep() step1.set_action(sample_action, step1) step2 = ActionStep() step2.set_action(sample_action, step2) step3 = ConditionStep() step3.set_evaluation(raw_input) step4 = ActionStep() step4.set_action(sample_action, step4) step5 = ActionStep() step5.set_action(sample_action, step5) step6 = ConditionStep() step6.set_evaluation(raw_input) step7 = ActionStep() step7.set_action(sample_action, step7) step8 = ActionStep() step8.set_action(sample_action, step8) step9 = ConditionStep() step9.set_evaluation(raw_input) step1.set_next(step2) step2.set_next(step3) step4.set_next(step6) step5.set_next(step2) step7.set_next(None) step8.set_next(step9) step3.set_alternatives({'1':step4, '2':step5}) step6.set_alternatives({'a':step7, 'b':step8}) step9.set_alternatives({'s':step4, 'n':step7}) workflow.run_flow(step1)