Exemplo n.º 1
0
def test_requirementslog_ioerror(patchermock_real, tmpdir, capsys):
    with tmpdir.as_cwd():
        with Runner(virtualenv_reqs='virtualenv_reqs') as runner:
            log_file = runner.requirements_log_file

        os.remove(log_file)
        os.makedirs(log_file)

        with Runner(virtualenv_reqs='virtualenv_reqs',
                    virtualenv_reqs_upd='True'):
            print('out')

    out, _ = capsys.readouterr()
    assert 'Error in {} file operation'.format(log_file) in out
    assert 'out' in out
Exemplo n.º 2
0
def test_runner(mock_os_path_isfile, mock_subprocess_check_call,
                mock_activateenv):
    with Runner() as runner:
        runner.run('cmd')

    assert (mock_subprocess_check_call.mock_calls[0] == mock.call(
        'cmd', shell=True, env={'name': 'value'}, stdout=None))
Exemplo n.º 3
0
def test_install_command_fail(tmpdir, mock_subprocess_popen_fail):
    with tmpdir.as_cwd():
        with pytest.raises(RunnerInstallationFailed) as excinfo:
            with Runner(virtualenv_reqs='virtualenv_reqs'):
                assert 0

    assert str(excinfo.value).startswith("Command execution of 'virtualenv")
    assert str(excinfo.value).endswith("' failed with exit status 1")
Exemplo n.º 4
0
def test_requirements_pip_raises_ioerror(
        tmpdir, mock_subprocess_popen_pip_raises_ioerror, capsys):
    with tmpdir.as_cwd():
        with pytest.raises(IOError) as excinfo:
            with Runner(virtualenv_reqs='virtualenv_reqs'):
                assert 0

    assert str(excinfo.value) == 'message'
Exemplo n.º 5
0
def test_setup_pydistutilscfg(patchermock_real, tmpdir, pip_indexes):
    with tmpdir.as_cwd():
        for pip_index in pip_indexes:
            with Runner(pip_index_url=pip_index) as runner:
                with open(runner.pydistutilscfg) as f:
                    assert f.read() == ('[easy_install]\n'
                                        'index_url={index}\n'.format(
                                            index=pip_indexes[0]))
Exemplo n.º 6
0
def test_init_without_none(mock_run):
    runner = Runner(virtualenv_dir='virtualenv_dir',
                    virtualenv_reqs='virtualenv_reqs',
                    virtualenv_pythonexe='virtualenv_pythonexe',
                    pip_index_url='pip_index_url',
                    run=mock_run)
    assert runner.virtualenv_dir == 'virtualenv_dir'
    assert runner.virtualenv_reqs == 'virtualenv_reqs'
    assert runner.virtualenv_pythonexe == 'virtualenv_pythonexe'
    assert runner.pip_index_url == 'pip_index_url'
Exemplo n.º 7
0
def test_install_requirements(mock_subprocess_check_call, tmpdir,
                              patchermock_real, capsys):
    with tmpdir.as_cwd():
        with Runner(virtualenv_reqs='virtualenv_reqs'):
            print('out')

    _, args, _ = patchermock_real.patch.mock_calls[1]
    assert args[0] == 'pip install -r virtualenv_reqs'
    out, _ = capsys.readouterr()
    assert 'out' in out
Exemplo n.º 8
0
def mock_requirements_log_file_raises_tmpdir(request, tmpdir):
    with tmpdir.as_cwd():

        mfile = MockFile(filename=Runner().requirements_log_file,
                         content="reguirements install log")

        def exception(*args, **kwargs):
            raise Exception('message')

        mfile.set_side_effect(exception)
        create_patch(mfile, request)
        return tmpdir
Exemplo n.º 9
0
def test_create_environment(mock_subprocess_check_call, patchermock_real,
                            mock_activateenv, mock_os_path_isfile_false,
                            tmpdir):
    with tmpdir.as_cwd():
        with Runner() as runner:
            runner.run('cmd')

        _, args, _ = patchermock_real.patch.mock_calls[0]
        assert args[0] == 'virtualenv --no-download -p python {}'.format(
            os.path.join(os.getcwd(), '.venv'))
        assert (mock_subprocess_check_call.mock_calls[0] == mock.call(
            'cmd', shell=True, env={'name': 'value'}, stdout=None))
Exemplo n.º 10
0
def test_install_requirements_from_index(mock_subprocess_check_call,
                                         patchermock_real, tmpdir, repeat_run):
    with tmpdir.as_cwd():
        for _ in range(repeat_run):
            with Runner(pip_index_url='pip_index_url',
                        virtualenv_reqs='virtualenv_reqs') as runner:
                runner_log_file = runner.requirements_log_file

    _, args, kwargs = patchermock_real.patch.mock_calls[1]
    assert kwargs['env'] == runner.env
    assert args == ('pip install -r virtualenv_reqs -i pip_index_url', )
    assert kwargs['shell']
    with open(runner_log_file) as f:
        assert f.read() == repeat_run * ('pip install out\n'
                                         'pip install err\n\n'
                                         '####################\n'
                                         'pip freeze:\n'
                                         'reqspec1\n'
                                         'reqspec2\n'
                                         'pip freeze err\n'
                                         '####################\n')
Exemplo n.º 11
0
def test_init_with_none(mock_gettempdir):
    runner = Runner()
    assert runner._virtualenv_dir is None  # pylint: disable=protected-access
    assert runner.virtualenv_reqs is None
    assert runner.virtualenv_pythonexe == 'python'
Exemplo n.º 12
0
def mock_pydistutilscfg(request):
    mfile = MockFile(filename=Runner().pydistutilscfg)
    create_patch(mfile, request)
    return mfile
Exemplo n.º 13
0
def test_remove_virtualenv(mock_shutil_rmtree, mock_os_path_isfile,
                           mock_subprocess_check_call):
    Runner().remove_virtualenv()
    mock_shutil_rmtree.assert_called_once_with(os.path.join(
        os.getcwd(), '.venv'),
                                               ignore_errors=True)
Exemplo n.º 14
0
def test_runner_changed_run(mock_tempfile_mkdtemp, mock_shutil_rmtree,
                            mock_run, mock_os_path_isfile, mock_activateenv):
    with Runner(run=mock_run) as runner:
        runner.run('cmd')

    assert (mock_run.mock_calls[0] == mock.call('cmd', env={'name': 'value'}))