Exemple #1
0
    def test_abort(self):
        self.x = None

        abort_if_not_none = self.abort_if_not_none
        assign = self.assign

        m = Mock()

        # test unaborted workflow 
        w = Workflow(steps=[abort_if_not_none, m])
        w(DefaultContext())
        assert m.called

        # test simple aborted workflow
        m.reset_mock()
        self.x = 1
        w = Workflow(steps=[abort_if_not_none, m])
        w(DefaultContext())
        assert not m.called

        # test mid workflow abort
        m.reset_mock()
        self.x = None
        w = Workflow(steps=[abort_if_not_none,
                            lambda context: assign(True),
                            abort_if_not_none,
                            m])
        w(DefaultContext())
        assert self.x is True
        assert not m.called
Exemple #2
0
 def test_custom_on_error(self):
     m = Mock(side_effect=ValueError)
     m_f = Mock(return_value=1)
     w = Workflow(steps=[m], on_error=m_f)
     r = w(DefaultContext())
     assert m.called
     assert m_f.called
     assert r == 1
Exemple #3
0
 def test_custom_on_abort(self):
     # test custom abort
     m = Mock()
     m_a = Mock()
     self.x = 1
     w = Workflow(steps=[self.abort_if_not_none, m],
                  on_abort=m_a)
     w(DefaultContext())
     assert not m.called
     assert m_a.called
Exemple #4
0
    def test_reply_abort(self):
        self.x = None
        abort_if_not_none = self.abort_if_not_none
        assign = self.assign
        reply = self.reply

        # assert that replies carry through
        self.x = None
        w = Workflow(steps=[abort_if_not_none, reply, reply,
                            lambda context: assign(True),
                            abort_if_not_none, reply])
        ctx = w(DefaultContext())
        assert ctx.replies == [1, 1]
Exemple #5
0
    MakePie(),
    arg_map={MakePie.MAKER: ThrowPieContext.THROWER},
    # we bind from the returned result back to the context
    result_map=MakePie.ResultMap(ThrowPieContext))
ThrowThingStep = Step(ThrowThing(),
                      arg_map=ThrowThing.AutoMap({
                          ThrowThing.ACTOR:
                          ThrowPieContext.THROWER,
                          ThrowThing.THING:
                          ThrowPieContext.PIE
                      }),
                      result_map={ThrowPieContext.WAS_HIT: 'hit'})
""" There are a few ways to build up a workflow. By constructor..."""
ThrowPieWorkflowA = Workflow(steps=[
    IsUserAuthorizedStep,
    MakePieStep,
    ThrowThingStep,
])
""" Or using add_step..."""
ThrowPieWorkflowB = Workflow().add_step(IsUserAuthorizedStep).add_step(
    MakePieStep).add_step(ThrowThingStep)
""" Or using the overloaded addition operator."""
EmptyWorkflow = Workflow()
ThrowPieWorkflowC_A = EmptyWorkflow + IsUserAuthorizedStep + MakePieStep
ThrowPieWorkflowC_B = EmptyWorkflow + ThrowThingStep
ThrowPieWorkflowC = ThrowPieWorkflowC_A + ThrowPieWorkflowC_B


def run():
    """To execute a workflow, prepare a context, and pass it through."""
    ctx = ThrowPieContext()
Exemple #6
0
    def test_default_on_error(self):
        m = Mock(side_effect=ValueError)

        w = Workflow(steps=[m])
        with nose.tools.assert_raises(ValueError):  # @UndefinedVariable
            w(DefaultContext())
Exemple #7
0
 def test_bad_concatenation(self):
     with nose.tools.assert_raises(TypeError):
         Workflow() + 10
Exemple #8
0
 def test_skip(self):
     w = Workflow(steps=[self.skip])
     ctx = w(DefaultContext())
     assert ctx.replies == []