def test_equality(self):
        step_result_1 = StepResult(result='foo', return_value='bar')
        step_result_2 = StepResult(result='foo', return_value='bar')
        self.assertEqual(step_result_1, step_result_2)

        step_result_3 = StepResult(result='new_foo', return_value='bar')
        self.assertNotEqual(step_result_1, step_result_3)
    def test_instance(self):
        step_result = StepResult(result='foo', return_value='bar')

        # Check attributes
        self.assertEqual(step_result.result, 'foo')
        self.assertEqual(step_result.return_value, 'bar')

        self.assertEqual(repr(step_result),
                         'StepResult(result=\'foo\', return_value=\'bar\')')
    def test_step_manager(self):
        def action_function(trail_env, context):
            return 'test return value {}'.format(context)

        step = Step(action_function)
        step.tags[
            'n'] = 7  # Typically this is set automatically. We're setting this manually for testing purposes.
        step.result_queue = MagicMock()
        trail_environment = MagicMock()
        step_manager(step, (trail_environment, ), dict(context='foo'))

        expected_result = StepResult(result=Step.SUCCESS,
                                     return_value='test return value foo')
        step.result_queue.put.assert_called_once_with(expected_result)
    def test_step_manager_with_exception(self):
        def action_function(trail_env, context):
            raise Exception('test exception')
            return 'test return value'

        step = Step(action_function)
        step.tags[
            'n'] = 7  # Typically this is set automatically. We're setting this manually for testing purposes.
        step.result_queue = MagicMock()
        trail_environment = MagicMock()
        step_manager(step, trail_environment, context='foo')

        expected_result = StepResult(result=Step.PAUSED_ON_FAIL,
                                     return_value='test exception')
        step.result_queue.put.assert_called_once_with(expected_result)