示例#1
0
def test_get_run_command_raises_when_command_not_found(_patched_red_text):
    commands = ['invalid']
    with pytest.raises(SystemExit) as e:
        util.get_run_command(commands)

    assert 1 == e.value.code
    msg = "ERROR: Command not found 'invalid'"
    _patched_red_text.assert_called_once_with(msg)
示例#2
0
def test_get_run_command():
    commands = [
        'ls',
        '-l',
    ]
    x = '{} -l'.format(plumbum.local.which('ls'))

    assert x == str(util.get_run_command(commands))
示例#3
0
def test_run_command_streams_stderr_on_failure(capsys):
    commands = [
        'python',
        '-c',
        'import sys; sys.exit("stderr")',
    ]
    cmd = util.get_run_command(commands)
    util.run_command(cmd, stream=True)

    captured = capsys.readouterr()
    assert 'stderr\n' == captured.out
示例#4
0
def test_run_command_raises_and_prints_stderr_on_failure(_patched_red_text):
    commands = [
        'python',
        '-c',
        'import sys; sys.exit("stderr")',
    ]
    with pytest.raises(SystemExit) as e:
        cmd = util.get_run_command(commands)
        util.run_command(cmd)

    assert 1 == e.value.code
    msg = 'ERROR: Command failed to execute\n\nstderr\n'
    _patched_red_text.assert_called_once_with(msg)
示例#5
0
def test_run_command_streams_stdout(capsys):
    cmd = util.get_run_command(['echo', 'stdout'])
    util.run_command(cmd, stream=True)

    captured = capsys.readouterr()
    assert 'stdout\n' == captured.out
示例#6
0
def test_run_command():
    cmd = util.get_run_command(['echo', 'foo'])
    x = (0, 'foo\n')

    assert x == util.run_command(cmd)