Ejemplo 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
Ejemplo n.º 2
0
    def test_result_mapper_str(self):
        m = Mock()
        m.return_value = {'returned': 'bar'}
        ctx = DefaultContext()
        ctx.baz = None
        with patch('inspect.getargspec') as argspec:
            argspec.return_value = [[]]
            Step(m, result_map={'baz': 'returned'})(ctx)

        assert m.called
        assert ctx.baz == 'bar'
Ejemplo n.º 3
0
    def test_result_mapper_callable(self):
        m = Mock()
        m.return_value = {'returned': ['abc', 'bar']}
        ctx = DefaultContext()
        ctx.baz = None

        def reverse_and_join(result, context): #@UnusedVariable
            return "".join(result['returned'])[::-1]

        with patch('inspect.getargspec') as argspec:
            argspec.return_value = [[]]
            Step(m, result_map={'baz': reverse_and_join})(ctx)

        assert m.called
        assert ctx.baz == 'rabcba'
Ejemplo n.º 4
0
    def test_arg_mapper(self):
        m = Mock()
        m._accepts_context = False
        ctx = DefaultContext()
        ctx.message = 1
        ctx.meow = 1

        with patch('inspect.getargspec') as argspec:
            argspec.return_value = [[]]
            Step(m, arg_map={'message': 'message'})(ctx)
            Step(m, arg_map={'meow': 'message'})(ctx)

        assert m.called
        m.assert_any_call(message=1)
        m.assert_any_call(meow=1)
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
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]
Ejemplo n.º 8
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())
Ejemplo n.º 9
0
 def test_skip(self):
     w = Workflow(steps=[self.skip])
     ctx = w(DefaultContext())
     assert ctx.replies == []