Exemplo n.º 1
0
def test_parse_multiple_args_without_equal():
    """
    Parsing multiple -e options to "run".
    :return:
    """
    text = 'run --name boo -e FOO 1 -e BOO 2 ubuntu'
    tokens = shlex.split(text) if text else ['']
    cmd = tokens[0]
    params = tokens[1:]

    with pytest.raises(OptionError) as ex:
        parse_command_options(cmd, params)
        assert 'KEY=VALUE' in ex.message
Exemplo n.º 2
0
def test_parse_multiple_args_without_equal():
    """
    Parsing multiple -e options to "run".
    :return:
    """
    text = 'run --name boo -e FOO 1 -e BOO 2 ubuntu'
    tokens = shlex.split(text) if text else ['']
    cmd = tokens[0]
    params = tokens[1:]

    with pytest.raises(OptionError) as ex:
        parse_command_options(cmd, params)
        assert 'KEY=VALUE' in ex.message
Exemplo n.º 3
0
def test_parse_run():
    """
    Test parsing of a simple "run"
    """
    parser, popts, pargs = parse_command_options(
        'run', ['--name', 'boo', 'ubuntu'])
    assert pargs == ['ubuntu']
    assert popts['name'] == 'boo'
Exemplo n.º 4
0
def test_parse_run_command_with_dash_arg():
    """
    Test parsing of a "run" with command to run and parameter, unquoted
    """
    parser, popts, pargs = parse_command_options(
        'run', ['--name', 'boo', 'ubuntu', 'top', '-b'])
    assert pargs == ['ubuntu', 'top', '-b']
    assert popts['name'] == 'boo'
Exemplo n.º 5
0
def test_parse_run_command():
    """
    Test parsing of a "run" with command to run
    """
    parser, popts, pargs = parse_command_options(
        'run', ['--name', 'boo', 'ubuntu', 'top'])
    assert pargs == ['ubuntu', 'top']
    assert popts['name'] == 'boo'
Exemplo n.º 6
0
def test_parse_run():
    """
    Test parsing of a simple "run"
    """
    parser, popts, pargs = parse_command_options('run',
                                                 ['--name', 'boo', 'ubuntu'])
    assert pargs == ['ubuntu']
    assert popts['name'] == 'boo'
Exemplo n.º 7
0
def test_parse_run_command_with_dash_arg():
    """
    Test parsing of a "run" with command to run and parameter, unquoted
    """
    parser, popts, pargs = parse_command_options(
        'run',
        ['--name', 'boo', 'ubuntu', 'top', '-b'])
    assert pargs == ['ubuntu', 'top', '-b']
    assert popts['name'] == 'boo'
Exemplo n.º 8
0
def test_parse_run_command():
    """
    Test parsing of a "run" with command to run
    """
    parser, popts, pargs = parse_command_options(
        'run',
        ['--name', 'boo', 'ubuntu', 'top'])
    assert pargs == ['ubuntu', 'top']
    assert popts['name'] == 'boo'
Exemplo n.º 9
0
def test_external_command_line(text, is_long, expected):
    """
    Parse and reconstruct the command line.
    """
    cmd, params = text.split(' ', 1)
    params = shlex.split(params)

    parser, popts, pargs = parse_command_options(cmd, params)

    result = format_command_line(cmd, is_long, pargs, popts)

    result_words = set(result.split(' ')[1:])
    expected_words = set(expected.split(' '))

    assert result_words == expected_words
Exemplo n.º 10
0
def test_external_command_line(text, is_long, expected):
    """
    Parse and reconstruct the command line.
    """
    cmd, params = text.split(' ', 1)
    params = shlex.split(params)

    parser, popts, pargs = parse_command_options(cmd, params)

    result = format_command_line(cmd, is_long, pargs, popts)

    result_words = set(result.split(' ')[1:])
    expected_words = set(expected.split(' '))

    assert result_words == expected_words
Exemplo n.º 11
0
def test_parse_multiple_args():
    """
    Parsing multiple -e options to "run".
    :return:
    """
    expected_opts = {
        'tty': False,
        'help': None,
        'remove': None,
        'environment': [u'FOO=1', u'BOO=2'],
        'detach': None,
        'name': u'boo'
    }

    expected_args = ['ubuntu']

    parser, popts, pargs = parse_command_options(
        'run', ['--name', 'boo', '-e', 'FOO=1', '-e', 'BOO=2', 'ubuntu'])

    assert pargs == expected_args
    for expected_key in expected_opts:
        assert expected_key in popts
        assert popts[expected_key] == expected_opts[expected_key]
Exemplo n.º 12
0
def test_parse_multiple_args():
    """
    Parsing multiple -e options to "run".
    :return:
    """
    expected_opts = {
        'tty': False,
        'help': None,
        'remove': None,
        'environment': [u'FOO=1', u'BOO=2'],
        'detach': None,
        'name': u'boo'
    }

    expected_args = ['ubuntu']

    parser, popts, pargs = parse_command_options(
        'run',
        ['--name', 'boo', '-e', 'FOO=1', '-e', 'BOO=2', 'ubuntu'])

    assert pargs == expected_args
    for expected_key in expected_opts:
        assert expected_key in popts
        assert popts[expected_key] == expected_opts[expected_key]
Exemplo n.º 13
0
def test_parse_images_help(help_opt_name):
    """
    Test parsing of a "--help"
    """
    parser, popts, pargs = parse_command_options('images', [help_opt_name])
    assert popts['help'] is True
Exemplo n.º 14
0
def test_parse_images_help(help_opt_name):
    """
    Test parsing of a "--help"
    """
    parser, popts, pargs = parse_command_options('images', [help_opt_name])
    assert popts['help'] is True