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()
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()
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
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
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)
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)
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)
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
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 == ''
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
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)
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
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'
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
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
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'
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
def test_run_not_found(make_one): command = make_one(['nonexistentcmd']) with pytest.raises(nox.command.CommandFailed): command.run()
def test_run_defaults(make_one, capsys): command = make_one([PYTHON, '-c', 'print(123)']) result = command.run() assert result is True