# Path: kale/exceptions.py
# class ImproperlyConfiguredException(Exception):
# class TaskException(Exception):
# class ChubbyTaskException(TaskException):
# class TimeoutException(TaskException):
# class InvalidTimeLimitTaskException(TaskException):
# class InvalidTaskDelayException(TaskException):
# class BlacklistedException(TaskException):
# class QueueException(Exception):
# class SendMessagesException(QueueException):
# class DeleteMessagesException(QueueException):
# class ChangeMessagesVisibilityException(QueueException):
#     def __init__(self, msg_count):
#     def __init__(self, msg_count):
#     def __init__(self, msg_count):
# 
# Path: kale/task.py
# PERMANENT_FAILURE_UNRECOVERABLE = 'unrecoverable'
# PERMANENT_FAILURE_NO_RETRY = 'no_retries'
# PERMANENT_FAILURE_RETRIES_EXCEEDED = 'max_retries'
#     EXCEPTION_LIST = (
#         exceptions.BlacklistedException,
#         KeyError,
#         NotImplementedError,
#         SyntaxError,
#         UnboundLocalError)
# class Task(object):
#     def __init__(self, message_body=None, *args, **kwargs):
#     def _get_publisher():
#     def _get_task_id(cls, *args, **kwargs):
#     def publish(cls, app_data, *args, **kwargs):
#     def _get_delay_sec_for_retry(cls, current_retry_num):
#     def handle_failure(cls, message, raised_exception, increment_failure_num=True):
#     def republish(cls, message, failure_count):
#     def run(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def should_run_task(self, *args, **kwargs):
#     def _check_blacklist(self, *args, **kwargs):
#     def _dequeued(self, *args, **kwargs):
#     def _setup_task_environment():
#     def _clean_task_environment(task_id=None, task_name=None, exc=None):
#     def _pre_run(self, *args, **kwargs):
#     def _post_run(self, *args, **kwargs):
#     def _alert_runtime_exceeded(self, *args, **kwargs):
#     def _kill_runtime_exceeded(self, *args, **kwargs):
#     def _report_permanent_failure(cls, message, exception, failure_type,
#                                   log_exception):
# 
# Path: kale/test_utils.py
# class MockTask(task.Task):
# class FailTask(task.Task):
# class ShouldNotRunTask(task.Task):
# class TimeoutTask(task.Task):
# class SlowButNotTooSlowTask(task.Task):
# class FailTaskNoRetries(FailTask):
# class MockMessage(message.KaleMessage):
# class MockConsumer(object):
# class TestQueueClass(queue_info.TaskQueue):
# class TestQueueSelector(queue_selector.SelectQueueBase):
#     def _get_task_id(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def _get_task_id(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def _get_task_id(cls, *args, **kwargs):
#     def should_run_task(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def _get_task_id(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def _get_task_id(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def __init__(self, task_inst, task_args=None, task_kwargs=None, app_data=None,
#                  retry_num=0, failure_num=0):
#     def consume(*args, **kwargs):
#     def __init__(self, queue_info):
#     def get_queue(self, *args, **kwargs):
# def new_mock_message(task_class=None):
# def new_mock_task(task_class=None):


import mock
import unittest
from kale import exceptions
from kale import task
from kale import test_utils
from six.moves import range
        task_args = [1, 'a']

        with self.assertRaises(exceptions.BlacklistedException):
            task_inst.run(*task_args)

        setup_env.assert_called_once_with()
        pre_run.assert_called_once_with(*task_args)
        self.assertFalse(run_task.called)
        clean_env.assert_called_once_with(
            task_id='mock_task', task_name='kale.test_utils.MockTask',
            exc=raised_exc)

    def testBlacklistedTaskNoRetries(self):
        """Test that a blacklisted task raises an exception."""
        setup_env = self._create_patch(
            'kale.task.Task._setup_task_environment')
        pre_run = self._create_patch('kale.task.Task._pre_run')
        run_task = self._create_patch('kale.task.Task.run_task')
        clean_env = self._create_patch(
            'kale.task.Task._clean_task_environment')
        check_blacklist = self._create_patch('kale.task.Task._check_blacklist')
        raised_exc = exceptions.BlacklistedException()
        check_blacklist.side_effect = raised_exc

        mock_message = test_utils.new_mock_message(
            task_class=test_utils.MockTask)
        task_inst = mock_message.task_inst
        task_inst._start_time = 1
        task_args = [1, 'a']


# Path: kale/exceptions.py
# class ImproperlyConfiguredException(Exception):
# class TaskException(Exception):
# class ChubbyTaskException(TaskException):
# class TimeoutException(TaskException):
# class InvalidTimeLimitTaskException(TaskException):
# class InvalidTaskDelayException(TaskException):
# class BlacklistedException(TaskException):
# class QueueException(Exception):
# class SendMessagesException(QueueException):
# class DeleteMessagesException(QueueException):
# class ChangeMessagesVisibilityException(QueueException):
#     def __init__(self, msg_count):
#     def __init__(self, msg_count):
#     def __init__(self, msg_count):
# 
# Path: kale/task.py
# PERMANENT_FAILURE_UNRECOVERABLE = 'unrecoverable'
# PERMANENT_FAILURE_NO_RETRY = 'no_retries'
# PERMANENT_FAILURE_RETRIES_EXCEEDED = 'max_retries'
#     EXCEPTION_LIST = (
#         exceptions.BlacklistedException,
#         KeyError,
#         NotImplementedError,
#         SyntaxError,
#         UnboundLocalError)
# class Task(object):
#     def __init__(self, message_body=None, *args, **kwargs):
#     def _get_publisher():
#     def _get_task_id(cls, *args, **kwargs):
#     def publish(cls, app_data, *args, **kwargs):
#     def _get_delay_sec_for_retry(cls, current_retry_num):
#     def handle_failure(cls, message, raised_exception, increment_failure_num=True):
#     def republish(cls, message, failure_count):
#     def run(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def should_run_task(self, *args, **kwargs):
#     def _check_blacklist(self, *args, **kwargs):
#     def _dequeued(self, *args, **kwargs):
#     def _setup_task_environment():
#     def _clean_task_environment(task_id=None, task_name=None, exc=None):
#     def _pre_run(self, *args, **kwargs):
#     def _post_run(self, *args, **kwargs):
#     def _alert_runtime_exceeded(self, *args, **kwargs):
#     def _kill_runtime_exceeded(self, *args, **kwargs):
#     def _report_permanent_failure(cls, message, exception, failure_type,
#                                   log_exception):
# 
# Path: kale/test_utils.py
# class MockTask(task.Task):
# class FailTask(task.Task):
# class ShouldNotRunTask(task.Task):
# class TimeoutTask(task.Task):
# class SlowButNotTooSlowTask(task.Task):
# class FailTaskNoRetries(FailTask):
# class MockMessage(message.KaleMessage):
# class MockConsumer(object):
# class TestQueueClass(queue_info.TaskQueue):
# class TestQueueSelector(queue_selector.SelectQueueBase):
#     def _get_task_id(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def _get_task_id(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def _get_task_id(cls, *args, **kwargs):
#     def should_run_task(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def _get_task_id(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def _get_task_id(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def __init__(self, task_inst, task_args=None, task_kwargs=None, app_data=None,
#                  retry_num=0, failure_num=0):
#     def consume(*args, **kwargs):
#     def __init__(self, queue_info):
#     def get_queue(self, *args, **kwargs):
# def new_mock_message(task_class=None):
# def new_mock_task(task_class=None):


# Path: kale/tests/test_task.py
import mock
import unittest
from kale import exceptions
from kale import task
from kale import test_utils
from six.moves import range

        task_args = [1, 'a']

        with self.assertRaises(exceptions.BlacklistedException):
            task_inst.run(*task_args)

        setup_env.assert_called_once_with()
        pre_run.assert_called_once_with(*task_args)
        self.assertFalse(run_task.called)
        clean_env.assert_called_once_with(
            task_id='mock_task', task_name='kale.test_utils.MockTask',
            exc=raised_exc)

    def testBlacklistedTaskNoRetries(self):
        """Test that a blacklisted task raises an exception."""
        setup_env = self._create_patch(
            'kale.task.Task._setup_task_environment')
        pre_run = self._create_patch('kale.task.Task._pre_run')
        run_task = self._create_patch('kale.task.Task.run_task')
        clean_env = self._create_patch(
            'kale.task.Task._clean_task_environment')
        check_blacklist = self._create_patch('kale.task.Task._check_blacklist')
        raised_exc = exceptions.BlacklistedException()
        check_blacklist.side_effect = raised_exc

        mock_message = test_utils.new_mock_message(
            task_class=test_utils.MockTask)
        task_inst = mock_message.task_inst
        task_inst._start_time = 1
        task_args = [1, 'a']


        with self.assertRaises(exceptions.BlacklistedException):