def test_prompt_user_for_step(): with patch(input_function) as mock_raw_input: dep = test_step.MockStep(name='mock_step', run_exception=RuntimeError('Exception while running step')) e = Executor(name='test_executor') global times_called times_called = 0 def raw_input_output(*args, **kwargs): global times_called times_called += 1 responses = ['y','','r',''] prompt = kwargs.get('prompt', args[0]) assert 'mock_step' in prompt assert 'Does this test work (y)/(n)?' in prompt return responses[times_called - 1] mock_raw_input.side_effect = raw_input_output assert e.prompt_user_for_step(step=dep, prompt='Does this test work (y)/(n)?') == 'y' assert e.prompt_user_for_step(step=dep, prompt='Does this test work (y)/(n)?', valid_choices=['d','r']) == 'r' assert e.prompt_user_for_step(step=dep, prompt='Does this test work (y)/(n)?', default='n') == 'n' e.execution = Execution() e.execution.aborted = True try: e.prompt_user_for_step(step=dep, prompt='Does this test work (y)/(n)?') except ExecutorAborted: pass else: assert False, 'Should have raised an ExecutorAborted exception if it was previously aborted'
def test_attach_self_as_executor(): e = Executor(name='test_executor') assert e.scan_interval == 0.0 assert e.execution is None assert e.user_input_class is ConsoleInput assert e.on_failure is Executor.RAISE dep = test_step.MockStep(name='mock_step') e.dependencies.add(dep) e.execution = Execution(executor=e) assert dep.executor is e assert dep.root_log_id == e.root_log_id
def test_execute_graceful_shutdown_with_already_aborted_execution(): dep = test_step.MockStep(name='mock_sibling_step') dep2 = test_step.MockStep(name='mock_sibling_step2', run_exception=RuntimeError("test_run_exception")) successful_dep = test_step.MockStep(name='successful_dep') parent = test_step.MockStep(name='mock_parent_step', dependencies=[dep, dep2, successful_dep]) assert parent.dependencies == {dep, dep2, successful_dep} successful_parent = test_step.MockStep(name='mock_successful_parent', dependencies=[successful_dep]) e = Executor(name='test_executor', on_failure=Executor.GRACEFUL_SHUTDOWN, dependencies=[parent, successful_parent]) e.execution = Execution(executor=e) e.execution.aborted = True e.execute() assert dep.status.pending assert dep2.status.pending assert successful_dep.status.pending assert parent.status.pending assert successful_parent.status.pending
def test_prompt_user_for_step(): with patch(input_function) as mock_raw_input: dep = test_step.MockStep( name='mock_step', run_exception=RuntimeError('Exception while running step')) e = Executor(name='test_executor') global times_called times_called = 0 def raw_input_output(*args, **kwargs): global times_called times_called += 1 responses = ['y', '', 'r', ''] prompt = kwargs.get('prompt', args[0]) assert 'mock_step' in prompt assert 'Does this test work (y)/(n)?' in prompt return responses[times_called - 1] mock_raw_input.side_effect = raw_input_output assert e.prompt_user_for_step( step=dep, prompt='Does this test work (y)/(n)?') == 'y' assert e.prompt_user_for_step(step=dep, prompt='Does this test work (y)/(n)?', valid_choices=['d', 'r']) == 'r' assert e.prompt_user_for_step(step=dep, prompt='Does this test work (y)/(n)?', default='n') == 'n' e.execution = Execution() e.execution.aborted = True try: e.prompt_user_for_step(step=dep, prompt='Does this test work (y)/(n)?') except ExecutorAborted: pass else: assert False, 'Should have raised an ExecutorAborted exception if it was previously aborted'