def test_pype_use_parent_context_with_swallow(mock_run_pipeline): """Input pype swallowing error in child pipeline.""" mock_run_pipeline.side_effect = mocked_run_pipeline_with_runtime_error context = Context({ 'pype': { 'name': 'pipe name', 'pipeArg': 'argument here', 'useParentContext': True, 'skipParse': True, 'raiseError': False, 'loader': 'test loader' } }) context.pipeline_name = 'og pipe name' with patch_logger('pypyr.steps.pype', logging.ERROR) as mock_logger_error: pype.run_step(context) assert context.pipeline_name == 'og pipe name' mock_run_pipeline.assert_called_once_with( pipeline_name='pipe name', pipeline_context_input=['argument', 'here'], context=context, parse_input=False, loader='test loader', groups=None, success_group=None, failure_group=None) mock_logger_error.assert_called_once_with( 'Something went wrong pyping pipe name. RuntimeError: whoops')
def test_pype_use_parent_context_swallow_stop_error(mock_run_pipeline): """Input pype doesn't swallow stop error in child pipeline.""" mock_run_pipeline.side_effect = mocked_run_pipeline_with_stop context = Context({ 'pype': { 'name': 'pipe name', 'pipeArg': 'argument here', 'useParentContext': True, 'skipParse': True, 'raiseError': False } }) context.pipeline_name = 'og pipe name' with patch_logger('pypyr.steps.pype', logging.ERROR) as mock_logger_error: with pytest.raises(Stop) as err_info: pype.run_step(context) assert isinstance(err_info.value, Stop) assert context.pipeline_name == 'og pipe name' mock_run_pipeline.assert_called_once_with( pipeline_name='pipe name', pipeline_context_input=['argument', 'here'], context=context, parse_input=False, loader=None, groups=None, success_group=None, failure_group=None) mock_logger_error.assert_not_called()
def test_pype_set_groups(mock_run_pipeline): """Input pype use_parent_context True.""" context = Context({ 'pype': { 'name': 'pipe name', 'pipeArg': 'argument here', 'useParentContext': True, 'skipParse': True, 'raiseError': True, 'loader': 'test loader', 'groups': 'testgroup', 'success': 'successgroup', 'failure': 'failuregroup' } }) with patch_logger('pypyr.steps.pype', logging.INFO) as mock_logger_info: pype.run_step(context) mock_run_pipeline.assert_called_once_with( pipeline_name='pipe name', pipeline_context_input='argument here', context=context, parse_input=False, loader='test loader', groups=['testgroup'], success_group='successgroup', failure_group='failuregroup') assert mock_logger_info.mock_calls == [ call('pyping pipe name, using parent context.'), call('pyped pipe name.') ]
def test_pype_no_pipe_arg(mock_run_pipeline): """Input pype use_parent_context False.""" context = Context({ 'pype': { 'name': 'pipe name', 'pipeArg': None, 'useParentContext': False, 'skipParse': False, 'raiseError': True, } }) context.working_dir = 'arb/dir' with patch_logger('pypyr.steps.pype', logging.INFO) as mock_logger_info: pype.run_step(context) mock_run_pipeline.assert_called_once_with(pipeline_name='pipe name', pipeline_context_input=None, context={}, parse_input=True, loader=None, groups=None, success_group=None, failure_group=None) assert mock_logger_info.mock_calls == [ call('pyping pipe name, without parent context.'), call('pyped pipe name.') ]
def test_pype_use_parent_context(mock_run_pipeline): """Input pype use_parent_context True.""" mock_run_pipeline.side_effect = mocked_run_pipeline context = Context({ 'pype': { 'name': 'pipe name', 'pipeArg': 'argument here', 'useParentContext': True, 'skipParse': True, 'raiseError': True, 'loader': 'test loader' } }) context.pipeline_name = 'og pipe name' with patch_logger('pypyr.steps.pype', logging.INFO) as mock_logger_info: pype.run_step(context) mock_run_pipeline.assert_called_once_with( pipeline_name='pipe name', pipeline_context_input=['argument', 'here'], context=context, parse_input=False, loader='test loader', groups=None, success_group=None, failure_group=None) assert context.pipeline_name == 'og pipe name' assert mock_logger_info.mock_calls == [ call('pyping pipe name, using parent context.'), call('pyped pipe name.') ]
def test_pype_use_parent_context_no_swallow(mock_run_pipeline): """Input pype without swallowing error in child pipeline.""" context = Context({ 'pype': { 'name': 'pipe name', 'pipeArg': 'argument here', 'useParentContext': True, 'skipParse': True, 'raiseError': True } }) with patch_logger('pypyr.steps.pype', logging.ERROR) as mock_logger_error: with pytest.raises(RuntimeError) as err_info: pype.run_step(context) assert str(err_info.value) == "whoops" mock_run_pipeline.assert_called_once_with( pipeline_name='pipe name', pipeline_context_input='argument here', context=context, parse_input=False, loader=None, groups=None, success_group=None, failure_group=None) mock_logger_error.assert_called_once_with( 'Something went wrong pyping pipe name. RuntimeError: whoops')
def test_pype_use_parent_context(mock_run_pipeline): """pype use_parent_context True.""" context = Context({ 'pype': { 'name': 'pipe name', 'pipeArg': 'argument here', 'useParentContext': True, 'skipParse': True, 'raiseError': True } }) logger = logging.getLogger('pypyr.steps.pype') with patch.object(logger, 'info') as mock_logger_info: pype.run_step(context) mock_run_pipeline.assert_called_once_with( pipeline_name='pipe name', pipeline_context_input='argument here', context=context, parse_input=False) assert mock_logger_info.mock_calls == [ call('pyping pipe name, using parent context.'), call('pyped pipe name.') ]
def test_pype_use_parent_context_no_swallow(mock_run_pipeline): """pype without swallowing error in child pipeline.""" context = Context({ 'pype': { 'name': 'pipe name', 'pipeArg': 'argument here', 'useParentContext': True, 'skipParse': True, 'raiseError': True } }) logger = logging.getLogger('pypyr.steps.pype') with patch.object(logger, 'error') as mock_logger_error: with pytest.raises(RuntimeError) as err_info: pype.run_step(context) assert repr(err_info.value) == "RuntimeError('whoops',)" mock_run_pipeline.assert_called_once_with( pipeline_name='pipe name', pipeline_context_input='argument here', context=context, parse_input=False) mock_logger_error.assert_called_once_with( 'Something went wrong pyping pipe name. RuntimeError: whoops')
def test_pype_no_pipe_arg(mock_run_pipeline): """pype use_parent_context False.""" context = Context({ 'pype': { 'name': 'pipe name', 'pipeArg': None, 'useParentContext': False, 'skipParse': False, 'raiseError': True } }) context.working_dir = 'arb/dir' logger = logging.getLogger('pypyr.steps.pype') with patch.object(logger, 'info') as mock_logger_info: pype.run_step(context) mock_run_pipeline.assert_called_once_with(pipeline_name='pipe name', pipeline_context_input=None, working_dir='arb/dir', parse_input=True) assert mock_logger_info.mock_calls == [ call('pyping pipe name, without parent context.'), call('pyped pipe name.') ]
def test_pype_args_with_mapping_out(mock_run_pipeline): """Input pype args used as context with mapping out.""" context = Context({ 'parentkey': 'parentvalue', 'pype': { 'name': 'pipe name', 'args': { 'a': 'av', 'b': 'bv', 'c': 'cv' }, 'out': { 'new-a': 'a', 'new-c': 'c' } } }) context.working_dir = 'arb/dir' with patch_logger('pypyr.steps.pype', logging.INFO) as mock_logger_info: pype.run_step(context) mock_run_pipeline.assert_called_once_with(pipeline_name='pipe name', pipeline_context_input=None, context={ 'a': 'av', 'b': 'bv', 'c': 'cv' }, parse_input=False, loader=None, groups=None, success_group=None, failure_group=None) assert mock_logger_info.mock_calls == [ call('pyping pipe name, without parent context.'), call('pyped pipe name.') ] assert context == { 'parentkey': 'parentvalue', 'new-a': 'av', 'new-c': 'cv', 'pype': { 'name': 'pipe name', 'args': { 'a': 'av', 'b': 'bv', 'c': 'cv' }, 'out': { 'new-a': 'a', 'new-c': 'c' } } }
def test_pype_use_parent_context_with_args(mock_run_pipeline): """Input pype use_parent_context True with args.""" context = Context({ 'k1': 'v1', 'pype': { 'name': 'pipe name', 'args': { 'a': 'b' }, 'pipeArg': 'argument here', 'useParentContext': True, 'skipParse': True, 'raiseError': True, 'loader': 'test loader' } }) with patch_logger('pypyr.steps.pype', logging.INFO) as mock_logger_info: pype.run_step(context) merged_context = { 'a': 'b', 'k1': 'v1', 'pype': { 'name': 'pipe name', 'args': { 'a': 'b' }, 'pipeArg': 'argument here', 'useParentContext': True, 'skipParse': True, 'raiseError': True, 'loader': 'test loader' } } mock_run_pipeline.assert_called_once_with( pipeline_name='pipe name', pipeline_context_input='argument here', context=merged_context, parse_input=False, loader='test loader', groups=None, success_group=None, failure_group=None) assert mock_logger_info.mock_calls == [ call('pyping pipe name, using parent context.'), call('pyped pipe name.') ]