示例#1
0
def test_function_command_fail(make_one_func):
    mock_func = mock.MagicMock(side_effect=ValueError('123'))
    mock_func.__name__ = lambda self: 'mock_func'

    command = make_one_func(mock_func)

    with pytest.raises(nox.command.CommandFailed):
        command.run()
示例#2
0
def test_function_command_fail(make_one_func):
    mock_func = mock.MagicMock(side_effect=ValueError('123'))
    mock_func.__name__ = lambda self: 'mock_func'

    command = make_one_func(mock_func)

    with pytest.raises(nox.command.CommandFailed):
        command.run()
示例#3
0
def test_interrupt(make_one):
    command = make_one([PYTHON, '-c' '123'])

    mock_proc = mock.Mock()
    mock_proc.communicate.side_effect = KeyboardInterrupt()

    with mock.patch('subprocess.Popen', return_value=mock_proc):
        with pytest.raises(KeyboardInterrupt):
            command.run()
示例#4
0
def test_interrupt(make_one):
    command = make_one([PYTHON, '-c' '123'])

    mock_proc = mock.Mock()
    mock_proc.communicate.side_effect = KeyboardInterrupt()

    with mock.patch('subprocess.Popen', return_value=mock_proc):
        with pytest.raises(KeyboardInterrupt):
            command.run()
示例#5
0
def test_fail_with_silent(make_one, capsys):
    command = make_one([
        PYTHON, '-c', 'import sys; sys.stdout.write("out");'
        'sys.stderr.write("err"); sys.exit(1)'
    ],
                       silent=True)

    with pytest.raises(nox.command.CommandFailed):
        command.run()
        out, err = capsys.readouterr()
        assert 'out' in err
        assert 'err' in err
示例#6
0
def test_fail_with_silent(make_one, capsys):
    command = make_one(
        [PYTHON, '-c',
         'import sys; sys.stdout.write("out");'
         'sys.stderr.write("err"); sys.exit(1)'],
        silent=True)

    with pytest.raises(nox.command.CommandFailed):
        command.run()
        out, err = capsys.readouterr()
        assert 'out' in err
        assert 'err' in err
示例#7
0
def test_run_path_existent(make_one, tmpdir, monkeypatch):
    executable = tmpdir.join('testexc')
    executable.ensure('')
    executable.chmod(0o700)

    command = make_one(['testexc'], silent=True, path=tmpdir.strpath)

    with mock.patch('nox.command.popen') as mock_command:
        mock_command.return_value = (0, '')
        command.run()
        mock_command.assert_called_with([executable.strpath],
                                        env=None,
                                        silent=True)
示例#8
0
def test_run_path_existent(make_one, tmpdir, monkeypatch):
    executable = tmpdir.join('testexc')
    executable.ensure('')
    executable.chmod(0o700)

    command = make_one(
        ['testexc'],
        silent=True,
        path=tmpdir.strpath)

    with mock.patch('nox.command.popen') as mock_command:
        mock_command.return_value = (0, '')
        command.run()
        mock_command.assert_called_with(
            [executable.strpath], env=None, silent=True)
示例#9
0
def test_function_command_callable(make_one_func):
    mock_func = mock.MagicMock()

    command = make_one_func(mock_func, [1], {'two': 3})

    assert command.run()
    mock_func.assert_called_with(1, two=3)
示例#10
0
def test_run_env(make_one):
    command = make_one(
        [PYTHON, '-c', 'import os; print(os.environ["SIGIL"])'],
        silent=True, env={'SIGIL': '123'})

    result = command.run()

    assert '123' in result
示例#11
0
def test_run_silent(make_one, capsys):
    command = make_one([PYTHON, '-c', 'print(123)'], silent=True)

    result = command.run()
    out, _ = capsys.readouterr()

    assert '123' in result
    assert out == ''
示例#12
0
def test_function_command(make_one_func):
    mock_func = mock.MagicMock()
    mock_func.__name__ = lambda self: 'mock_func'

    command = make_one_func(mock_func)

    assert command.run()
    assert mock_func.called
示例#13
0
def test_function_command(make_one_func):
    mock_func = mock.MagicMock()
    mock_func.__name__ = lambda self: 'mock_func'

    command = make_one_func(mock_func, [1], {'two': 3})

    assert command.run()
    mock_func.assert_called_with(1, two=3)
示例#14
0
def test_run_path_nonexistent(make_one):
    command = make_one([PYTHON, '-c', 'import sys; print(sys.executable)'],
                       silent=True,
                       path='/non/existent')

    result = command.run()

    assert '/non/existent' not in result
示例#15
0
def test_run_silent(make_one, capsys):
    command = make_one([PYTHON, '-c', 'print(123)'], silent=True)

    result = command.run()
    out, _ = capsys.readouterr()

    assert '123' in result
    assert out == ''
示例#16
0
def test_env_no_fallback(make_one):
    command = make_one([PYTHON, '-c', 'import os; print(os.environ["SIGIL"])'],
                       silent=True,
                       env={u'SIGIL': u'123'})

    result = command.run()

    assert result.strip() == '123'
示例#17
0
def test_run_env(make_one):
    command = make_one([PYTHON, '-c', 'import os; print(os.environ["SIGIL"])'],
                       silent=True,
                       env={'SIGIL': '123'})

    result = command.run()

    assert '123' in result
示例#18
0
def test_function_command(make_one_func):
    mock_func = mock.MagicMock()
    mock_func.__name__ = lambda self: 'mock_func'

    command = make_one_func(mock_func)

    assert command.run()
    assert mock_func.called
示例#19
0
def test_run_path_nonexistent(make_one):
    command = make_one(
        [PYTHON, '-c', 'import sys; print(sys.executable)'],
        silent=True,
        path='/non/existent')

    result = command.run()

    assert '/non/existent' not in result
示例#20
0
def test_run_env_fallback(make_one):
    command = make_one(
        [PYTHON, '-c',
         'import os; print(os.environ["SIGIL"] + os.environ["SIGIL2"] )'],
        silent=True)

    result = command.run(env_fallback={u'SIGIL': u'abc', u'SIGIL2': u'456'})

    assert result.strip() == 'abc456'
示例#21
0
def test_run_env_systemroot(make_one):
    systemroot = os.environ.setdefault('SYSTEMROOT', str('sigil'))

    command = make_one(
        [PYTHON, '-c', 'import os; print(os.environ["SYSTEMROOT"])'],
        silent=True)

    result = command.run()

    assert systemroot in result
示例#22
0
def test_run_not_found(make_one):
    command = make_one(['nonexistentcmd'])

    with pytest.raises(nox.command.CommandFailed):
        command.run()
示例#23
0
def test_run_defaults(make_one, capsys):
    command = make_one([PYTHON, '-c', 'print(123)'])

    result = command.run()

    assert result is True
示例#24
0
def test_run_defaults(make_one, capsys):
    command = make_one([PYTHON, '-c', 'print(123)'])

    result = command.run()

    assert result is True
示例#25
0
def test_run_not_found(make_one):
    command = make_one(['nonexistentcmd'])

    with pytest.raises(nox.command.CommandFailed):
        command.run()