def test_call_full_init_no_runner(self):
        # given
        task = self.MockedTask()

        # then
        with self.assertRaises(NonRecoverableError):
            # when
            run_with(None).call(
                task,
                self.mocked_ctx,
                *self.some_args,
                **self.some_kwargs
            )
    def test_call_full_unknown_exception(self):
        # given
        def task(args, kwargs, **rp):
            raise KeyError()

        # then
        with self.assertRaises(RecoverableError):
            # when
            run_with(**self.default_init_input_args).call(
                task,
                self.mocked_ctx,
                *self.some_args,
                **self.some_kwargs
            )
    def test_call_full_init_common_nonrecoverable_exception(self):
        # given
        def task(args, kwargs, **rp):
            raise RuntimeError()

        # then
        with self.assertRaises(NonRecoverableError):
            # when
            run_with(**self.default_init_input_args).call(
                task,
                self.mocked_ctx,
                *self.some_args,
                **self.some_kwargs
            )
    def test_call_full_init_no_exceptions(self):
        # given
        task = self.MockedTask()

        # when
        run_with(**self.default_init_input_args).call(
            task,
            self.mocked_ctx,
            *self.some_args,
            **self.some_kwargs
        )

        # then
        self.assertEquals(len(task.calls), 1)
        self.assert_default_call(task.calls[0])
    def test_call_full_init_nonrecoverable_exception(self):
        # given
        def task(args, kwargs, **rp):
            raise AttributeError()

        decorators.COMMON_RECOVERABLE_EXCEPTIONS = (AttributeError)

        # then
        with self.assertRaises(RecoverableError):
            # when
            run_with(**self.default_init_input_args).call(
                task,
                self.mocked_ctx,
                *self.some_args,
                **self.some_kwargs
            )
    def test_call_minimal_init_no_exceptions(self):
        # given
        task = self.MockedTask()

        # when
        run_with(self.default_runner_class).call(
            task,
            self.mocked_ctx,
        )

        # then
        self.assertEquals(len(task.calls), 1)

        call = task.calls[0]
        self.assertEquals(call.ctx, self.mocked_ctx)
        self.assertEquals(call.resolving_rules, [])
        self.assertEquals(call.sources_order, SOURCES_DEFAULT_ORDER)
        self.assertEquals(call.api_ctx_provider_cls, None)
        self.assertEquals(call.args, ())
        self.assertEquals(call.kwargs, {})
    def test__call__(self):
        # given
        task = self.MockedTask()
        mocked_run_with_call = Mock()
        rw = run_with(**self.default_init_input_args)
        rw.call = mocked_run_with_call

        # when
        rw(task)(self.mocked_ctx, self.some_args, self.some_kwargs)

        # then
        mocked_run_with_call.assert_called_once()