Esempio 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
Esempio 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
Esempio 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'
Esempio 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'
Esempio 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'
Esempio 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'
Esempio 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'
Esempio 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'
Esempio 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
Esempio 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
Esempio 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]
Esempio 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]
Esempio 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
Esempio 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