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, [])
def test_step_to_stepstatus_with_non_json_serializable_return_value(self): step = Step(lambda x: x, n=0) mock_exception = TypeError('is not JSON serializable') step.return_value = mock_exception step_status = step_to_stepstatus(step, [ StatusField.STATE, StatusField.RETURN_VALUE, StatusField.TAGS, StatusField.OUTPUT_MESSAGES, StatusField.PROMPT_MESSAGES, StatusField.UNREPLIED_PROMPT_MESSAGE ]) self.assertEqual( step_status, { StatusField.N: 0, StatusField.NAME: str(step), StatusField.TAGS: step.tags, StatusField.STATE: Step.READY, StatusField.RETURN_VALUE: str(mock_exception), StatusField.OUTPUT_MESSAGES: [], StatusField.PROMPT_MESSAGES: [], StatusField.UNREPLIED_PROMPT_MESSAGE: None })