# Path: caravan/tests/fixtures.py
# class TestWorkflow1(Workflow):
# class TestWorkflow2(Workflow):
# 
# Path: caravan/tests/util.py
# def mock_args(args):
#     return mock.patch('sys.argv', ['PROG'] + args)
# 
# Path: caravan/commands/decider.py
# class Command(BaseCommand):
# 
#     description = 'Decider worker'
# 
#     def setup_arguments(self, parser):
#         parser.add_argument('-m', '--modules',
#                             type=ClassesLoaderFromModule(Workflow),
#                             nargs='+',
#                             required=True)
#         parser.add_argument('-d', '--domain',
#                             required=True)
#         parser.add_argument('-t', '--task-list',
#                             required=True)
#         parser.add_argument('--register-workflows', action='store_true')
# 
#     def run(self):
#         connection = get_connection()
#         workflows = [w for module in self.args.modules for w in module]
# 
#         if self.args.register_workflows:
#             log.info("Registering workflow types")
#             for workflow in workflows:
#                 created = register_workflow(connection=connection,
#                                             domain=self.args.domain,
#                                             workflow=workflow)
#                 if created:
#                     log.info("Workflow type %s(%s): registered.",
#                              workflow.name, workflow.version)
#                 else:
#                     log.info("Workflow type %s(%s): already registered.",
#                              workflow.name, workflow.version)
# 
#         log.info("Start decider worker...")
#         worker = Worker(connection=connection,
#                         domain=self.args.domain,
#                         task_list=self.args.task_list,
#                         workflows=workflows)
# 
#         while True:
#             try:
#                 worker.run()
#             except Exception:  # Doesn't catch KeyboardInterrupt
#                 log.exception("Decider crashed!")
# 
# Path: caravan/commands/decider.py
# class Command(BaseCommand):
#     def setup_arguments(self, parser):
#     def run(self):


import unittest
import mock
import caravan
from caravan.tests import fixtures
from caravan.tests.util import mock_args
from caravan.commands.decider import Command
from caravan.commands.decider import ClassesLoaderFromModule




@mock.patch('caravan.commands.decider.Worker')
class Test(unittest.TestCase):

    def test_nominal(self, m_worker_cls):
        m_worker = m_worker_cls.return_value
        m_worker.run.side_effect = [None, None, KeyboardInterrupt('KILLTEST')]

        args = [
            '-d', 'DOMAIN', '-m', 'caravan.tests.fixtures', '-t', 'TASKLIST',
            ]


# Path: caravan/tests/fixtures.py
# class TestWorkflow1(Workflow):
# class TestWorkflow2(Workflow):
# 
# Path: caravan/tests/util.py
# def mock_args(args):
#     return mock.patch('sys.argv', ['PROG'] + args)
# 
# Path: caravan/commands/decider.py
# class Command(BaseCommand):
# 
#     description = 'Decider worker'
# 
#     def setup_arguments(self, parser):
#         parser.add_argument('-m', '--modules',
#                             type=ClassesLoaderFromModule(Workflow),
#                             nargs='+',
#                             required=True)
#         parser.add_argument('-d', '--domain',
#                             required=True)
#         parser.add_argument('-t', '--task-list',
#                             required=True)
#         parser.add_argument('--register-workflows', action='store_true')
# 
#     def run(self):
#         connection = get_connection()
#         workflows = [w for module in self.args.modules for w in module]
# 
#         if self.args.register_workflows:
#             log.info("Registering workflow types")
#             for workflow in workflows:
#                 created = register_workflow(connection=connection,
#                                             domain=self.args.domain,
#                                             workflow=workflow)
#                 if created:
#                     log.info("Workflow type %s(%s): registered.",
#                              workflow.name, workflow.version)
#                 else:
#                     log.info("Workflow type %s(%s): already registered.",
#                              workflow.name, workflow.version)
# 
#         log.info("Start decider worker...")
#         worker = Worker(connection=connection,
#                         domain=self.args.domain,
#                         task_list=self.args.task_list,
#                         workflows=workflows)
# 
#         while True:
#             try:
#                 worker.run()
#             except Exception:  # Doesn't catch KeyboardInterrupt
#                 log.exception("Decider crashed!")
# 
# Path: caravan/commands/decider.py
# class Command(BaseCommand):
#     def setup_arguments(self, parser):
#     def run(self):


# Path: caravan/tests/commands/test_decider.py
import unittest
import mock
import caravan
from caravan.tests import fixtures
from caravan.tests.util import mock_args
from caravan.commands.decider import Command
from caravan.commands.decider import ClassesLoaderFromModule





@mock.patch('caravan.commands.decider.Worker')
class Test(unittest.TestCase):

    def test_nominal(self, m_worker_cls):
        m_worker = m_worker_cls.return_value
        m_worker.run.side_effect = [None, None, KeyboardInterrupt('KILLTEST')]

        args = [
            '-d', 'DOMAIN', '-m', 'caravan.tests.fixtures', '-t', 'TASKLIST',
            ]


        with mock_args(args):