Exemplo n.º 1
0
def test_run_env(mock_popen):
    run('cmd', env={'name': 'value'})
    mock_popen.assert_called_once_with('cmd',
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       shell=True,
                                       env={'name': 'value'})
Exemplo n.º 2
0
def test_result_false(mock_popen):
    mock_popen.return_value.returncode = 1
    with pytest.raises(Failure) as excinfo:
        run('cmd')
    r = excinfo.value.args[0]
    assert r.cmd == 'cmd'
    assert r.stdout == 'out'
    assert r.stderr == 'err'
    assert str(r) == 'cmd: cmd\nstdout:\nout\nstderr:\nerr\nreturncode: 1'
Exemplo n.º 3
0
def test_run_ignore_codes_raises(mock_popen):
    mock_popen.return_value.returncode = 2
    with pytest.raises(Failure) as excinfo:
        run('cmd', ignore_codes=[1])
    r = excinfo.value.args[0]
    assert r.cmd == 'cmd'
    assert r.stdout == 'out'
    assert r.stderr == 'err'
    assert str(r) == 'cmd: cmd\nstdout:\nout\nstderr:\nerr\nreturncode: 2'
Exemplo n.º 4
0
def sdist(deploy=False, remove_dist=False):
    """Create source distribution.

    Args:
        deploy:       Register and upload sdist to PyPI.
        remove_dist:  Control is 'dist' directory initially removed or not.
    """
    clean(remove_dist=remove_dist, create_dirs=True)
    run('python setup.py sdist' + (' register upload' if deploy else ''))
    announce()
Exemplo n.º 5
0
def help():
    """Show help, basically an alias for --help.

    This task can be removed once the fix to this issue is released:
    https://github.com/pyinvoke/invoke/issues/180
    """
    print(run(
        'invoke -r {moduledir} --help'.format(moduledir=MODULEDIR)).stdout)
Exemplo n.º 6
0
def test_run_replaced_output(mock_popen):
    r = run(cmd='cmd', replaced_output='replaced_output')
    assert r.returncode == 0
    assert r.cmd == 'replaced_output'
    assert r.stdout == ''
    assert r.stderr == ''
    assert (str(r) ==
            'cmd: replaced_output\nstdout:\n\nstderr:\n\nreturncode: 0')
Exemplo n.º 7
0
def test_run_ignore_codes(mock_popen):
    mock_popen.return_value.returncode = 2
    r = run(cmd='cmd', ignore_codes=[2, 20, 123])
    assert r.returncode == 2
    assert r.cmd == 'cmd'
    assert r.stdout == 'out'
    assert r.stderr == 'err'
    assert (str(r) ==
            'cmd: cmd\nstdout:\nout\nstderr:\nerr\nreturncode: 2')
Exemplo n.º 8
0
def test_run(mock_popen):
    r = run('cmd')
    mock_popen.assert_called_once_with('cmd',
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       shell=True)
    assert r.returncode == 0
    assert r.stdout == 'out'
    assert r.stderr == 'err'
    assert (str(r) ==
            'cmd: cmd\nstdout:\nout\nstderr:\nerr\nreturncode: 0')
Exemplo n.º 9
0
 def verboserun(cmd, **kwargs):
     kwargs_copy = kwargs.copy()
     kwargs_copy['verbose'] = verbose
     return run(cmd, **kwargs_copy)
Exemplo n.º 10
0
def test_verbose(capsys, mock_popen):
    run(cmd='cmd', verbose=True)
    out, _ = capsys.readouterr()
    assert out == 'cmd: cmd\nstdout:\nout\nstderr:\nerr\nreturncode: 0\n'
Exemplo n.º 11
0
def test_run_return_stdout_and_stderr_is_unicode(mock_popen):
    mock_popen.return_value.communicate.return_value = (b'out', b'err')
    r = run('cmd')
    assert isinstance(r.stdout, str)
    assert isinstance(r.stderr, str)
Exemplo n.º 12
0
def test_run_shell(mock_popen, shell):
    run(cmd='cmd', shell=shell)
    mock_popen.assert_called_once_with('cmd',
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       shell=shell)
Exemplo n.º 13
0
def test_verbose_replaced_output(capsys, mock_popen):
    run(cmd='cmd', verbose=True, replaced_output='replaced_output')
    out, _ = capsys.readouterr()
    assert out == 'cmd: replaced_output\nstdout:\n\nstderr:\n\nreturncode: 0\n'