예제 #1
0
def test_handle_odd_setup_paths(setup_path, valid, mock_build_venv):
    pkger = VirtualEnvPackager("/tmp")
    if not valid:
        with pytest.raises(AssertionError):
            pkger.install_package(setup_path)
    else:
        pkger.install_package(setup_path)
예제 #2
0
def _package_virtualenv_with_manifest(manifest, requirements_file_path,
                                      setup_py_path):
    """
    Given a manifest, package up the virtualenv. The following methods are
    supported via the manifest's `method` setting:

    * copy: copy in the top-level directory
    * requirements: run ``pip install -r requirements_file``
        - useful if requirements_file contains '.'
    * pip: run ``pip install .``
    * install (default): run ``python setup.py install``
    """

    venv = manifest.local_virtualenv_path
    install_method = manifest.contents.get('method')

    # Buld virtualenv and optionally upgrade pip
    packager = VirtualEnvPackager(venv, manifest.upgrade_pip,
                                  manifest.upgrade_wheel)

    if install_method == 'copy':
        packager.copy_package(requirements_file_path,
                              manifest.local_package_path)

    elif install_method == 'requirements':
        packager.install_requirements(requirements_file_path)

    elif install_method == 'pip':
        packager.pip_install_package(requirements_file_path)

    else:
        packager.install_package(setup_py_path)

    return packager
예제 #3
0
def test_handle_odd_reqfile_paths(req_file_path, valid, mock_build_venv):

    if not valid:
        with pytest.raises(AssertionError):
            VirtualEnvPackager('/tmp').copy_package(req_file_path,
                                                    '/other/path')
    else:
        VirtualEnvPackager('/tmp').copy_package(req_file_path, '/other/path')
예제 #4
0
def test_handle_prelink_issue(mock_logger, mock_local, mock_build_venv):
    pkger = VirtualEnvPackager("/tmp")
    mock_local.reset_mock()
    mock_logger.reset_mock()
    assert not mock_local.called
    assert not mock_logger.called
    mock_local.side_effect = Exception
    pkger.remove_prelink_if_applicable()
    mock_logger.debug.assert_called_once_with("prelink not undone due to error", exc_info=True)
예제 #5
0
def test_handle_prelink_issue(mock_logger, mock_local, mock_build_venv):
    pkger = VirtualEnvPackager('/tmp')
    mock_local.reset_mock()
    mock_logger.reset_mock()
    assert not mock_local.called
    assert not mock_logger.called
    mock_local.side_effect = Exception
    pkger.remove_prelink_if_applicable()
    mock_logger.debug.assert_called_once_with(
        'prelink not undone due to error', exc_info=True)
예제 #6
0
def _package_virtualenv_with_manifest(manifest, requirements_file_path,
                                      setup_py_path):
    """
    Given a manifest, package up the virtualenv. The following methods are
    supported via the manifest's `method` setting:

    * copy: copy in the top-level directory
    * requirements: run ``pip install -r requirements_file``
        - useful if requirements_file contains '.'
    * pip: run ``pip install .``
    * install (default): run ``python setup.py install``
    """

    venv = manifest.local_virtualenv_path
    install_method = manifest.contents.get('method')

    # Buld virtualenv and optionally upgrade pip
    packager = VirtualEnvPackager(venv, manifest.upgrade_pip, manifest.upgrade_wheel)

    if install_method == 'copy':
        packager.copy_package(requirements_file_path,
                                manifest.local_package_path)

    elif install_method == 'requirements':
        packager.install_requirements(requirements_file_path)

    elif install_method == 'pip':
        packager.pip_install_package(requirements_file_path)

    else:
        packager.install_package(setup_py_path)

    return packager
예제 #7
0
    def test_with_spaces(self, monkeypatch, mock_local):
        monkeypatch.setattr("sys.executable", "/some/python.py")

        local_venv = "/local path/venv"
        remote_venv = "/remote path/venv"
        pkger = VirtualEnvPackager(local_venv)
        mock_local.reset_mock()
        assert not mock_local.called
        pkger.patch_virtualenv(remote_venv)
        assert mock_local.mock_calls == [
            mock.call("prelink -u '/local path/venv/bin/python'"),
            mock.call("/some/python.py -m virtualenv --relocatable " "'/local path/venv'"),
            mock.call('sed -i "s:/local path/venv:/remote path/venv:" ' "'/local path/venv/bin/activate'"),
        ]
예제 #8
0
 def test_pip_install(self, mock_local, venv, req, expected):
     assert mock_local.mock_calls == []
     with mock.patch('ship_it.virtualenv.VirtualEnvPackager.'
                     'install_requirements') as mock_install_reqs:
         VirtualEnvPackager(venv).pip_install_package(req)
         mock_install_reqs.assert_called_once_with(req)
     mock_local.assert_called_once_with(expected)
예제 #9
0
    def test_with_spaces(self, monkeypatch, mock_local):
        monkeypatch.setattr('sys.executable', '/some/python.py')

        local_venv = '/local path/venv'
        remote_venv = '/remote path/venv'
        pkger = VirtualEnvPackager(local_venv)
        mock_local.reset_mock()
        assert not mock_local.called
        pkger.patch_virtualenv(remote_venv)
        assert mock_local.mock_calls == [
            mock.call("prelink -u '/local path/venv/bin/python'"),
            mock.call("/some/python.py -m virtualenv --relocatable "
                      "'/local path/venv'"),
            mock.call('sed -i "s:/local path/venv:/remote path/venv:" '
                      "'/local path/venv/bin/activate'"),
        ]
예제 #10
0
def test_handle_odd_setup_paths(setup_path, valid, mock_build_venv):
    pkger = VirtualEnvPackager('/tmp')
    if not valid:
        with pytest.raises(AssertionError):
            pkger.install_package(setup_path)
    else:
        pkger.install_package(setup_path)
예제 #11
0
    def test_upgrade_wheel(self, upgrade_wheel, mock_local):
        assert mock_local.mock_calls == []
        pkger = VirtualEnvPackager('/tmp/foo', False, upgrade_wheel)

        if upgrade_wheel:
            upgrade_wheel_call = [
                mock.call('/tmp/foo/bin/pip install --upgrade wheel')
            ]
        else:
            upgrade_wheel_call = []
        assert mock_local.mock_calls == [
            mock.call("/path/to/python.py -m virtualenv /tmp/foo")
        ] + upgrade_wheel_call
예제 #12
0
    def test_exists(self, exists, mock_local):
        assert not mock_local.called
        with mock.patch('ship_it.virtualenv.path.exists', return_value=exists):
            VirtualEnvPackager('/my/local path/to/venv')

        if exists:
            # We expect that we're going to delete the directory
            rm_rf_call = [mock.call("rm -rf '/my/local path/to/venv'")]
        else:
            # We don't need to do that
            rm_rf_call = []

        assert mock_local.mock_calls == rm_rf_call + [
            mock.call(
                "/path/to/python.py -m virtualenv '/my/local path/to/venv'")
        ]
예제 #13
0
 def test_install_requirements(self, mock_local, venv, req, expected):
     assert not mock_local.called
     VirtualEnvPackager(venv).install_requirements(req)
     mock_local.assert_called_once_with(expected)
예제 #14
0
 def test_install_package(self, mock_local, venv, setup, expected):
     assert not mock_local.called
     VirtualEnvPackager(venv).install_package(setup)
     mock_local.assert_called_once_with(expected)
예제 #15
0
    def test_copy_package(self, mock_local, venv, pkg_dir, req, expected):

        assert not mock_local.called
        VirtualEnvPackager(venv).copy_package(req, pkg_dir)

        assert mock_local.mock_calls == [mock.call(exp) for exp in expected]