def test_env_name_error(): with pytest.raises(PipInstallError) as err: pip.pip_install(name="thisistotallynotthenameofanenvironment", packages=[]) assert str(err.value) == ( "Pip install [] failed with message: Could not find conda environment: thisistotallynotthenameofanenvironment\n" "You can list all discoverable environments with `conda info --envs`.\n\n" )
def install( self, packages: Packages, index_url: Union[str, ListLike] = PIP_DEFAULT_INDEX_URL, ) -> None: """Install/update pip packages""" pip_install(name=self.env.name, packages=packages, index_url=index_url) self.update_history_install(packages=packages, index_url=index_url) self.env.export()
def test_package_name_error(): name = os.environ.get("CONDA_DEFAULT_ENV") with pytest.raises(PipInstallError): pip.pip_install( name=name, packages=Packages.from_specs( ["thereisnowaysomeonewouldnameapackagethisway"] ), )
def test_pip_install_fail(mocker): name = "env_name" packages = [Package.from_spec("not_an_actual_pip_package")] run_mock = mocker.patch("conda_env_tracker.gateways.pip.subprocess.run") run_mock.configure_mock( **{"return_value.returncode": 1, "return_value.stderr": "error"} ) mocker.patch("os.environ.get", mocker.Mock(return_value=name)) with pytest.raises(PipInstallError) as err: pip.pip_install(name=name, packages=packages) assert ( str(err.value) == "Pip install ['not_an_actual_pip_package'] failed with message: error" )
def test_pip_install_success(name, packages, index, active_conda_env, expected, mocker): """Successfully calling the install command""" run_mock = mocker.patch("conda_env_tracker.gateways.pip.subprocess.run") run_mock.configure_mock(**{"return_value.returncode": 0}) mocker.patch( "conda_env_tracker.gateways.conda.get_conda_bin_path", mocker.Mock(return_value=Path.cwd()), ) mocker.patch("os.environ.get", mocker.Mock(return_value=active_conda_env)) if index: pip.pip_install(name=name, packages=packages, index_url=index) else: pip.pip_install(name=name, packages=packages) run_mock.assert_called_once_with( expected, shell=True, stderr=subprocess.PIPE, encoding="UTF-8" )