Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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]
Exemplo n.º 5
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())
Exemplo n.º 6
0
 def test_skip(self):
     w = Workflow(steps=[self.skip])
     ctx = w(DefaultContext())
     assert ctx.replies == []