コード例 #1
0
    def test_run_step(self):
        def action_function_a():
            return 'test return value'

        mock_args = MagicMock()
        mock_kwargs = MagicMock()
        mock_pre_processor = MagicMock(return_value=(mock_args, mock_kwargs))
        step = Step(action_function_a, pre_processor=mock_pre_processor)
        step.context = 'mock_context'
        step.tags['n'] = 0

        process_patcher = patch('autotrail.layer1.trail.Process')
        mock_process = process_patcher.start()

        run_step(step)

        process_patcher.stop()

        args, kwargs = mock_process.call_args
        arg_step, arg_args, arg_kwargs = kwargs['args']
        self.assertEqual(step, arg_step)
        self.assertEqual(arg_args, mock_args)
        self.assertEqual(arg_kwargs, mock_kwargs)
        self.assertEqual(kwargs['target'], step_manager)

        self.assertIn(mock.call().start(), mock_process.mock_calls)
        self.assertEqual(step.state, step.RUN)
コード例 #2
0
    def test_run_step_with_rerun_of_a_step(self):
        def action_function_a():
            return 'test return value'

        step = Step(action_function_a)
        step.tags['n'] = 0

        # Setup some old values for the step. Similar to the effect of running the step might have.
        step.return_value = 'Some old return value.'
        step.prompt_messages = ['old message 1', 'old message 2']
        step.input_messages = ['response to old message 1']

        process_patcher = patch('autotrail.layer1.trail.Process')
        mock_process = process_patcher.start()

        run_step(step, 'mock_context')

        process_patcher.stop()

        args, kwargs = mock_process.call_args
        arg_step, arg_trail_env, arg_context = kwargs['args']
        self.assertEqual(step, arg_step)
        self.assertIsInstance(arg_trail_env, TrailEnvironment)
        self.assertEqual(arg_context, 'mock_context')
        self.assertEqual(kwargs['target'], step_manager)

        self.assertIn(call().start(), mock_process.mock_calls)
        self.assertEqual(step.state, step.RUN)

        # Because the step is being re-run, the old values of the following attributes should get reset.
        self.assertEqual(step.return_value, None)
        self.assertEqual(step.prompt_messages, [])
        self.assertEqual(step.input_messages, [])
コード例 #3
0
    def test_run_step_when_pre_processor_fails(self):
        def action_function_a():
            return 'test return value'

        mock_exception = MockException()
        mock_pre_processor = MagicMock(side_effect=mock_exception)
        step = Step(action_function_a, pre_processor=mock_pre_processor)
        step.context = 'mock_context'
        step.tags['n'] = 0

        process_patcher = patch('autotrail.layer1.trail.Process')
        mock_process = process_patcher.start()

        run_step(step)

        process_patcher.stop()
        self.assertEqual(step.process, None)
        self.assertEqual(mock_process.mock_calls, [])
        self.assertEqual(step.state, step.FAILURE)
        self.assertEqual(step.return_value, mock_exception)
コード例 #4
0
    def test_run_step(self):
        def action_function_a():
            return 'test return value'

        step = Step(action_function_a)
        step.tags['n'] = 0

        process_patcher = patch('autotrail.layer1.trail.Process')
        mock_process = process_patcher.start()

        run_step(step, 'mock_context')

        process_patcher.stop()

        args, kwargs = mock_process.call_args
        arg_step, arg_trail_env, arg_context = kwargs['args']
        self.assertEqual(step, arg_step)
        self.assertIsInstance(arg_trail_env, TrailEnvironment)
        self.assertEqual(arg_context, 'mock_context')
        self.assertEqual(kwargs['target'], step_manager)

        self.assertIn(call().start(), mock_process.mock_calls)
        self.assertEqual(step.state, step.RUN)