コード例 #1
0
def test_pype_get_arguments_name_empty():
    """Empty pype name throw."""
    context = Context({'pype': {'name': None}})

    with pytest.raises(KeyInContextHasNoValueError) as err_info:
        pype.get_arguments(context)

    assert str(err_info.value) == ("pypyr.steps.pype ['pype']['name'] exists "
                                   "but is empty.")
コード例 #2
0
def test_pype_get_args_not_a_dict():
    """When args not a dict raise."""
    context = Context({'pype': {'name': 'blah', 'args': 'arb'}})

    with pytest.raises(ContextError) as err_info:
        pype.get_arguments(context)

    assert str(err_info.value) == (
        "pypyr.steps.pype 'args' in the 'pype' context item "
        "must be a dict.")
コード例 #3
0
def test_pype_get_arguments_missing_pype():
    """Missing pype throw."""
    context = Context()

    with pytest.raises(KeyNotInContextError) as err_info:
        pype.get_arguments(context)

    assert str(err_info.value) == ("context['pype'] "
                                   "doesn't exist. It must exist for "
                                   "pypyr.steps.pype.")
コード例 #4
0
def test_pype_get_arguments_missing_name():
    """Missing pype name throw."""
    context = Context({'pype': {}})

    with pytest.raises(KeyNotInContextError) as err_info:
        pype.get_arguments(context)

    assert str(err_info.value) == (
        "pypyr.steps.pype missing 'name' in the 'pype' "
        "context item. You need to specify the pipeline name to run another "
        "pipeline.")
コード例 #5
0
def test_pype_get_args_and_pipearg():
    """Combine pipeArgs and args. Defaults useParentContext to False."""
    context = Context({
        'pype': {
            'name': 'pipe name',
            'args': {
                'a': 'b'
            },
            'pipeArg': 'a b c',
        }
    })

    (pipeline_name, args, out, use_parent_context, pipe_arg, skip_parse,
     raise_error, loader, groups, success_group,
     failure_group) = pype.get_arguments(context)

    assert pipeline_name == 'pipe name'
    assert args == {'a': 'b'}
    assert out is None
    assert not use_parent_context
    assert pipe_arg == ['a', 'b', 'c']
    assert not skip_parse
    assert raise_error
    assert not loader
    assert not groups
    assert not success_group
    assert not failure_group
コード例 #6
0
def test_pype_get_arguments_group_str_interpolate():
    """Parse group as interpolated str input from context."""
    context = Context({
        'group': 'gr',
        'pype': {
            'name': 'pipe name',
            'groups': '{group}',
        }
    })

    (pipeline_name, args, out, use_parent_context, pipe_arg, skip_parse,
     raise_error, loader, groups, success_group,
     failure_group) = pype.get_arguments(context)

    assert pipeline_name == 'pipe name'
    assert args is None
    assert out is None
    assert use_parent_context
    assert isinstance(use_parent_context, bool)
    assert pipe_arg is None
    assert skip_parse
    assert isinstance(skip_parse, bool)
    assert raise_error
    assert isinstance(raise_error, bool)
    assert loader is None
    assert groups == ['gr']
    assert success_group is None
    assert failure_group is None
コード例 #7
0
def test_pype_get_arguments_all():
    """Parse all input from context."""
    context = Context({
        'pype': {
            'name': 'pipe name',
            'args': {
                'a': 'b'
            },
            'out': 'out value',
            'pipeArg': 'argument here',
            'useParentContext': False,
            'skipParse': 'skip parse',
            'raiseError': 'raise err',
            'loader': 'test loader',
            'groups': ['gr'],
            'success': 'sg',
            'failure': 'fg'
        }
    })

    (pipeline_name, args, out, use_parent_context, pipe_arg, skip_parse,
     raise_error, loader, groups, success_group,
     failure_group) = pype.get_arguments(context)

    assert pipeline_name == 'pipe name'
    assert args == {'a': 'b'}
    assert out == 'out value'
    assert not use_parent_context
    assert skip_parse == 'skip parse'
    assert raise_error == 'raise err'
    assert loader == 'test loader'
    assert groups == ['gr']
    assert success_group == 'sg'
    assert failure_group == 'fg'
コード例 #8
0
def test_pype_get_out_set_with_use_parent_context():
    """When out is present useParentContext must be false."""
    context = Context(
        {'pype': {
            'name': 'blah',
            'out': 'arb',
            'useParentContext': True
        }})

    with pytest.raises(ContextError) as err_info:
        pype.get_arguments(context)

    assert str(err_info.value) == (
        "pypyr.steps.pype pype.out is only "
        "relevant if useParentContext = False. If you're using the parent "
        "context, no need to have out args since their values will already be "
        "in context. If you're NOT using parent context and you've specified "
        "pype.args, just leave off the useParentContext key and it'll default "
        "to False under the hood, or set it to False yourself if you keep it "
        "in.")
コード例 #9
0
def test_pype_get_arguments_defaults():
    """Parse all input from context and assign defaults where not specified."""
    context = Context({'pype': {'name': 'pipe name'}})

    (pipeline_name, use_parent_context, pipe_arg, skip_parse,
     raise_error) = pype.get_arguments(context)

    assert pipeline_name == 'pipe name'
    assert use_parent_context
    assert isinstance(use_parent_context, bool)
    assert skip_parse
    assert isinstance(skip_parse, bool)
    assert raise_error
    assert isinstance(raise_error, bool)
コード例 #10
0
def test_pype_get_arguments_all_with_interpolation():
    """Parse all input from context."""
    context = Context({
        'pipeName': 'pipe name',
        'argsHere': {
            'a': '{pipeName}'
        },
        'outHere': 'out here',
        'argHere': 'argument here',
        'parentContext': False,
        'skipParse': 'skip parse',
        'raiseErr': 'raise err',
        'loaderHere': 'test loader',
        'groups': ['gr'],
        'success': 'sg',
        'failure': 'fg',
        'pype': {
            'name': '{pipeName}',
            'args': '{argsHere}',
            'out': '{outHere}',
            'pipeArg': '{argHere}',
            'useParentContext': '{parentContext}',
            'skipParse': '{skipParse}',
            'raiseError': '{raiseErr}',
            'loader': '{loaderHere}',
            'groups': '{groups}',
            'success': '{success}',
            'failure': '{failure}',
        }
    })

    (pipeline_name, args, out, use_parent_context, pipe_arg, skip_parse,
     raise_error, loader, groups, success_group,
     failure_group) = pype.get_arguments(context)

    assert pipeline_name == 'pipe name'
    assert args == {'a': 'pipe name'}
    assert out == 'out here'
    assert not use_parent_context
    assert pipe_arg == ['argument', 'here']
    assert skip_parse == 'skip parse'
    assert raise_error == 'raise err'
    assert loader == 'test loader'
    assert groups == ['gr']
    assert success_group == 'sg'
    assert failure_group == 'fg'
コード例 #11
0
def test_pype_get_arguments_all():
    """Parse all input from context."""
    context = Context({
        'pype': {
            'name': 'pipe name',
            'pipeArg': 'argument here',
            'useParentContext': 'parent context bool',
            'skipParse': 'skip parse',
            'raiseError': 'raise err'
        }
    })

    (pipeline_name, use_parent_context, pipe_arg, skip_parse,
     raise_error) = pype.get_arguments(context)

    assert pipeline_name == 'pipe name'
    assert use_parent_context == 'parent context bool'
    assert skip_parse == 'skip parse'
    assert raise_error == 'raise err'
コード例 #12
0
ファイル: pype_test.py プロジェクト: jizongFox/pypyr
def test_pype_get_arguments_defaults():
    """Parse all input from context and assign defaults where not specified."""
    context = Context({'pype': {'name': 'pipe name'}})

    (pipeline_name, args, out, use_parent_context, pipe_arg, skip_parse,
     raise_error, loader, groups, success_group,
     failure_group) = pype.get_arguments(context)

    assert pipeline_name == 'pipe name'
    assert not args
    assert not out
    assert use_parent_context
    assert isinstance(use_parent_context, bool)
    assert skip_parse
    assert isinstance(skip_parse, bool)
    assert raise_error
    assert isinstance(raise_error, bool)
    assert loader is None
    assert groups is None
    assert success_group is None
    assert failure_group is None
コード例 #13
0
def test_pype_get_pipeargs_no_skip_parse():
    """If pipeArgs set skipParse should default False."""
    context = Context({'pype': {
        'name': 'pipe name',
        'pipeArg': 'a b c',
    }})

    (pipeline_name, args, out, use_parent_context, pipe_arg, skip_parse,
     raise_error, loader, groups, success_group,
     failure_group) = pype.get_arguments(context)

    assert pipeline_name == 'pipe name'
    assert args is None
    assert out is None
    assert not use_parent_context
    assert pipe_arg == ['a', 'b', 'c']
    assert not skip_parse
    assert raise_error
    assert not loader
    assert not groups
    assert not success_group
    assert not failure_group
コード例 #14
0
ファイル: pype_test.py プロジェクト: jizongFox/pypyr
def test_pype_get_args_no_parent_context():
    """If args set use_parent_context should default False."""
    context = Context({'pype': {
        'name': 'pipe name',
        'args': {
            'a': 'b'
        },
    }})

    (pipeline_name, args, out, use_parent_context, pipe_arg, skip_parse,
     raise_error, loader, groups, success_group,
     failure_group) = pype.get_arguments(context)

    assert pipeline_name == 'pipe name'
    assert args == {'a': 'b'}
    assert not out
    assert not use_parent_context
    assert skip_parse
    assert raise_error
    assert not loader
    assert not groups
    assert not success_group
    assert not failure_group