Exemplo n.º 1
0
def _set_up_virtualenv(venv_name, tmp_dir, req,
                       include_packages, system_site_packages,
                       pypi_index_url, python_interpreter, verbose):
    """Create a virtualenv with the specified options and the default packages
    specified in configuration. Then run `pip install -r [requirements file]`.
    """
    venv = VirtualenvProxy(
        os.path.join(tmp_dir, venv_name),
        system_site_packages=system_site_packages,
        pypi_index_url=pypi_index_url,
        python_interpreter=python_interpreter,
        verbose=verbose
    )

    packages = ["pyleus=={0}".format(__version__)]
    if include_packages is not None:
        packages += include_packages

    for package in packages:
        venv.install_package(package)

    if req is not None:
        venv.install_from_requirements(req)

    _remove_pyleus_base_jar(venv)

    return venv
Exemplo n.º 2
0
    def test___init__(self, mock_create, mock_open):
        mock_open.return_value = 42
        venv = VirtualenvProxy(VENV_PATH, verbose=False)
        mock_open.assert_called_once_with(os.devnull, "w")
        assert venv._out_stream == 42
        mock_create.assert_called_once_with(venv)

        venv = VirtualenvProxy(VENV_PATH, verbose=True)
        assert mock_open.call_count == 1
        assert venv._out_stream is None
Exemplo n.º 3
0
 def test__create_virtualenv_system_site_packages(
         self, mock_cmd, mock_open):
     venv = VirtualenvProxy(VENV_PATH,
                            system_site_packages=True,
                            verbose=True)
     mock_cmd.assert_called_once_with(
         ["virtualenv", VENV_PATH, "--system-site-packages"],
         stdout=venv._out_stream,
         stderr=venv._err_stream,
         err_msg=mock.ANY
     )
Exemplo n.º 4
0
 def test__create_virtualenv_python_interpreter(
         self, mock_cmd, mock_open):
     path = "python2.7"
     venv = VirtualenvProxy(VENV_PATH,
                            python_interpreter=path,
                            verbose=True)
     mock_cmd.assert_called_once_with(
         ["virtualenv", VENV_PATH, "--python", path],
         stdout=venv._out_stream,
         stderr=venv._err_stream,
         err_msg=mock.ANY
     )
Exemplo n.º 5
0
def _set_up_virtualenv(venv_name, tmp_dir, req, include_packages,
                       system_site_packages, pypi_index_url,
                       python_interpreter, verbose):
    """Create a virtualenv with the specified options and the default packages
    specified in configuration. Then run `pip install -r [requirements file]`.
    """
    venv = VirtualenvProxy(os.path.join(tmp_dir, venv_name),
                           system_site_packages=system_site_packages,
                           pypi_index_url=pypi_index_url,
                           python_interpreter=python_interpreter,
                           verbose=verbose)

    packages = ["pyleus=={0}".format(__version__)]
    if include_packages is not None:
        packages += include_packages

    for package in packages:
        venv.install_package(package)

    if req is not None:
        venv.install_from_requirements(req)

    _remove_pyleus_base_jar(venv)

    return venv
Exemplo n.º 6
0
class TestVirtualenvProxyMethods(object):

    @pytest.fixture(autouse=True)
    @mock.patch.object(__builtin__, 'open', autospec=True)
    @mock.patch.object(VirtualenvProxy, '_create_virtualenv', autospec=True)
    def setup_virtualenv(self, mock_create, mock_open):
        self.venv = VirtualenvProxy(VENV_PATH,
                                    pypi_index_url=PYPI_URL,
                                    verbose=False)

    @mock.patch.object(virtualenv_proxy, '_exec_shell_cmd', autospec=True)
    def test_install_package(self, mock_cmd):
        self.venv.install_package("Ninja==7.7.7")
        mock_cmd.assert_called_once_with(
            [
                "{0}/bin/pip".format(VENV_PATH), "install", "Ninja==7.7.7",
                "-i", PYPI_URL,
                '--use-wheel',
            ],
            stdout=self.venv._out_stream,
            stderr=self.venv._err_stream,
            err_msg=mock.ANY
        )

    @mock.patch.object(virtualenv_proxy, '_exec_shell_cmd', autospec=True)
    def test_install_from_requirements(self, mock_cmd):
        self.venv.install_from_requirements("foo.txt")
        mock_cmd.assert_called_once_with(
            [
                "{0}/bin/pip".format(VENV_PATH), "install",
                "-r", "foo.txt",
                "-i", PYPI_URL,
                '--use-wheel',
            ],
            stdout=self.venv._out_stream,
            stderr=self.venv._err_stream,
            err_msg=mock.ANY
        )
Exemplo n.º 7
0
class TestVirtualenvProxyMethods(object):

    @pytest.fixture(autouse=True)
    @mock.patch.object(builtins, 'open', autospec=True)
    @mock.patch.object(VirtualenvProxy, '_create_virtualenv', autospec=True)
    def setup_virtualenv(self, mock_create, mock_open):
        self.venv = VirtualenvProxy(VENV_PATH,
                                    pypi_index_url=PYPI_URL,
                                    verbose=False)

    @mock.patch.object(virtualenv_proxy, '_exec_shell_cmd', autospec=True)
    def test_install_package(self, mock_cmd):
        self.venv.install_package("Ninja==7.7.7")
        mock_cmd.assert_called_once_with(
            [
                "{0}/bin/pip".format(VENV_PATH), "install", "Ninja==7.7.7",
                "-i", PYPI_URL,
                '--use-wheel',
            ],
            stdout=self.venv._out_stream,
            stderr=self.venv._err_stream,
            err_msg=mock.ANY
        )

    @mock.patch.object(virtualenv_proxy, '_exec_shell_cmd', autospec=True)
    def test_install_from_requirements(self, mock_cmd):
        self.venv.install_from_requirements("foo.txt")
        mock_cmd.assert_called_once_with(
            [
                "{0}/bin/pip".format(VENV_PATH), "install",
                "-r", "foo.txt",
                "-i", PYPI_URL,
                '--use-wheel',
            ],
            stdout=self.venv._out_stream,
            stderr=self.venv._err_stream,
            err_msg=mock.ANY
        )
Exemplo n.º 8
0
 def setup_virtualenv(self, mock_create, mock_open):
     self.venv = VirtualenvProxy(VENV_PATH,
                                 pypi_index_url=PYPI_URL,
                                 verbose=False)
Exemplo n.º 9
0
 def setup_virtualenv(self, mock_create, mock_open):
     self.venv = VirtualenvProxy(VENV_PATH,
                                 pypi_index_url=PYPI_URL,
                                 verbose=False)